2009-10-28 77 views
0
<data> 
<Attributes> 
<Attribute name='somethingelse' value='blah'/> 
<Attribute name='forms'> 
    <List> 
     <String>xform</String> 
     <String>yform</String> 
    </List> 
    </Attribute> 
</Attributes> 
</data> 

我已分析的屬性級別的XSLT,這樣我就可以通過只是在做<xsl:value-of select="Attribute[@name='somethingelse']/attribute::value"/>XSLT解析多行

獲得的價值等等我如何做一個選擇的有2串形式XFORM和yform。我想在同一行上獲取xform和yform。從其他線程有人給了我下面的代碼:

<xsl:template match="/"> 
    <xsl:for-each select="//String"> 
<xsl:value-of select="."/><xsl:if test="not(position() = last())">|</xsl:if> 
    </xsl:for-each> 
    </xsl:template> 

我不知道如何把它所有together.My的目標是有一個像輸出:

胡說,XForm的| yform

回答

1

不知道是否我收到了你的問題的權利,但我想這應該輸出你想要什麼:

<xsl:template match="/"> 
    <xsl:apply-templates select="//Attributes"/> 
</xsl:template> 

<xsl:template match="Attributes"> 
    <xsl:value-of select="Attribute[@name='somethingelse']/@value"/> 
    <xsl:text>,</xsl:text> 
    <xsl:for-each select="Attribute[@name='forms']/List/String"> 
    <xsl:value-of select="."/> 
    <xsl:if test="position() != last()">|</xsl:if> 
    </xsl:for-each> 
</xsl:template> 
0

您也可以分配給一個變量,像這樣:

<xsl:variable name="strings"> 
    <xsl:value-of select="concat(String[1],String[2],String[3])" /> 
</xsl:variable> 

第3個字符串是否存在並不重要。這是一種破解,我實際上對它進行了硬編碼,我的代碼在每個代碼之間添加了'###',以便我可以運行'contains($ strings,'### Keyword'),它基本上檢查是否有任何字符串以特定的字符串開始。