2012-04-27 3 views
1

I 다음 예제 XML이 :XSLT 주문 출력

Row: FName 
Row: LName 
Row: Email 
Row: Phone 
Row: Address 

이 목록 그러나해야하는 순서 : 나는의 출력에이 글을 읽을 수 있도록하려면

<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> 

을 행의 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 

답변

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>&#10;</xsl:text> 
</xsl:template> 
+0

잘 타이를 작동, 미래에 대한 종류로 모양을 – Mike