我有以下示例XML:
<Table>
<Row Position="0" Name="FName" />
<Row Position="1" Name="LName" />
<Row Position="2" Name="Email" />
<Row Position="3" Name="Phone" />
<Row Position="4" Name="Address" />
</Table>
我希望能够将其读入:
的输出Row: FName
Row: LName
Row: Email
Row: Phone
Row: Address
然而,此列表的排序应基于行的Position
属性,以便只需更改数字排序即可更改输出顺序。
我想这将需要一个或两个变量来完成但不完全确定执行。
干杯
示例:
输入
<Table>
<Row Position="0" Name="FName" />
<Row Position="1" Name="LName" />
<Row Position="4" Name="Email" />
<Row Position="2" Name="Phone" />
<Row Position="3" Name="Address" />
</Table>
输出
Row: FName
Row: LName
Row: Phone
Row: Address
Row: Email
答案 0 :(得分:2)
<xsl:template match="Table">
<xsl:apply-templates select="Row">
<xsl:sort select="@Position" data-type="number"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Row">
<xsl:text>Row: </xsl:text>
<xsl:value-of select="@Name"/>
<xsl:text> </xsl:text>
</xsl:template>