XSLT - 处理多个子节点

时间:2011-08-09 12:29:24

标签: xslt xslt-1.0

我必须编写和XSLT来处理以下XML:

<Attachments>
    <string>http://lurl/site/Lists/Note/Attachments/image1.jpg</string>
    <string>http://lurl/site/Lists/Note/Attachments/image3.jpg</string>
</Attachments>

我需要输出2个字符串,但是对于某些记录,还有2个字符串要输出。

e.g。

<ul>
  <li>http://lurl/site/Lists/Note/Attachments/image1.jpg</li>
  <li>http://lurl/site/Lists/Note/Attachments/image3.jpg</li>
</ul>

我需要每个还是

4 个答案:

答案 0 :(得分:2)

您不需要任何迭代。使用身份转换并覆盖:

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

    <xsl:output indent="yes"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Attachments">
        <ul>
            <xsl:apply-templates select="node()|@*"/>
        </ul>
    </xsl:template>

    <xsl:template match="string">
        <li><xsl:value-of select="."/></li>
    </xsl:template>

</xsl:stylesheet>

答案 1 :(得分:2)

一个简单的apply-templates应该这样做。

<xsl:template match="Attachments">
  <ul>
    <xsl:apply-templates/>
  </ul>
</xsl:template>

<xsl:template match="string">
  <li><xsl:value-of select="."/></li>
</xsl:template>

答案 2 :(得分:0)

一种方法是使用xsl:template

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:template match="/">
  <ul>
    <xsl:apply-templates />
  </ul>
</xsl:template>

<xsl:template match="/Attachments/string">
  <li>
    <xsl:value-of select="." />
  </li>
</xsl:template>
</xsl:stylesheet>

答案 3 :(得分:0)

<ul>
<xsl:for-each select="//Attachments/string">
  <li>
    <xsl:value-of select="text()" />
  </li>
</xsl:for-each>
</ul>
相关问题