XSLT-处理多个子节点
我必须编写和使用XSLT来处理以下XML:XSLT-处理多个子节点,xslt,xslt-1.0,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> http://lurl/site/
<Attachments>
<string>http://lurl/site/Lists/Note/Attachments/image1.jpg</string>
<string>http://lurl/site/Lists/Note/Attachments/image3.jpg</string>
</Attachments>
http://lurl/site/Lists/Note/Attachments/image1.jpg
http://lurl/site/Lists/Note/Attachments/image3.jpg
我需要输出2个字符串,尽管对于某些记录,要输出的字符串多于2个
e、 g
- http://lurl/site/Lists/Note/Attachments/image1.jpg
- http://lurl/site/Lists/Note/Attachments/image3.jpg
每个我需要一个,还是在时需要一个?您不需要任何类型的迭代。使用标识转换和替代:
<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>
一个简单的人应该可以做到这一点
<xsl:template match="Attachments">
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>
<xsl:template match="string">
<li><xsl:value-of select="."/></li>
</xsl:template>
一种方法是使用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>
-
@andyb谢谢,我已经加入了身份转换,因为它可能会在总体上有所帮助。如果问题中的示例XML如图所示那么简单,那么可以按照您的答案删除它。
<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>
<ul>
<xsl:for-each select="//Attachments/string">
<li>
<xsl:value-of select="text()" />
</li>
</xsl:for-each>
</ul>