2012-12-18 160 views
0

我有以下XML獲取兄弟節點的值在XSLT

<CN>12<CN> 
<CT>XYXY</CT> 

我需要的結果作爲

<DIV>12 XYXY</DIV> 

我使用floowing XSLT,但它不工作

<xsl:variable name="x"><xsl:value-of select="CN"/></xsl:variable> 

<xsl:template match="CT"> 
<div class="chap-title"><span><xsl:value-of select="$x"/></span></div> 
</xsl:template> 

回答

2

輸入:

<input> 
    <CN>12</CN> 
    <CT>XYXY</CT> 
</input> 

XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       version="2.0"> 

    <xsl:output indent="yes" 
       method="xml" 
       encoding="UTF-8" /> 

    <xsl:template match="/input"> 
     <DIV> 
      <xsl:value-of select="CN"/> 
      <xsl:text> </xsl:text> 
      <xsl:value-of select="CT"/> 
     </DIV> 
    </xsl:template> 

</xsl:stylesheet>