[英]xslt 1.0 sorting when grouping
Last time I had some problems with grouping on xslt 1.0. 上次我在对xslt 1.0进行分组时遇到了一些问题。 Now I've faced another problem with sorting. 现在,我在排序时遇到了另一个问题。 Here is some code. 这是一些代码。
XML XML
<Development>
<PlotTypes>
<Apartments>
<Building>
<PlotType Phase="1" />
<PlotType Phase="2" />
</Building>
</Apartments>
</PlotTypes>
<Phases>
<Phase ContentID="40514" PhaseCode="1" Title="Properties available to move in" SortOrder="2" />
<Phase ContentID="40515" PhaseCode="2" Title="test" SortOrder="1" />
</Phases>
</Development>
And here is XSLT 这是XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name ="phase" match="//PlotType" use="@Phase"/>
<xsl:template match="Development">
<xsl:for-each select="//PlotType[generate-id(.)=generate-id(key('phase',@Phase)[1])]">
<xsl:sort select="//Phase[@PhaseCode=@Phase]/@SortOrder" order="ascending" data-type="number"/>
<xsl:variable select="@Phase" name="groupedPhase"/>
Phase - <xsl:value-of select="@Phase"/><br/>
Phase Sort order - <xsl:value-of select="//Phase[@PhaseCode=$groupedPhase]/@SortOrder"/><br/>
<xsl:value-of select="//Phase[@PhaseCode=$groupedPhase]/@Title"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
And I need to make this final result 我需要做出最终结果
<?xml version="1.0" encoding="UTF-8"?>
Phase - 2<br/>
Phase Sort order - 2<br/>
<h3>test</h3>
Phase - 1<br/>
Phase Sort order - 1<br/>
<h3>Properties available to move in</h3>
But when I use such sorting <xsl:sort select="//Phase[@PhaseCode=@Phase]/@SortOrder"...
it doesn't work. 但是,当我使用这样的排序方式<xsl:sort select="//Phase[@PhaseCode=@Phase]/@SortOrder"...
它不起作用。
Define a second key 定义第二个键
<xsl:key name="phase-by-code" match="Phases/Phase" use="@PhaseCode"/>
then use 然后使用
<xsl:sort select="key('phase-by-code', @Phase)/@SortOrder" order="ascending" data-type="number"/>
for your sort. 为您的排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.