2011-08-09 20 views
2

の対処は、私は、次のXMLを扱うために書き、XSLTするんだ:XSLT - 複数の子-ノード

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

一部のレコードのためにもっとして2があるが、私は、2つの文字列を出力する必要があります出力する文字列。

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

はながら、私は、各またはためが必要ですか?

+0

XSLTを使用することです。 –

答えて

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

+1私は同じアイデアのために(そして私より速い!) – andyb

+0

@andybありがとう、私はそれが一般的に役立つかもしれない唯一のアイデンティティ変換を含んでいます。質問のサンプルXMLが示されているように単純な場合、答えに示されているように削除できます。 –

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> 
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> 
0
<ul> 
<xsl:for-each select="//Attachments/string"> 
    <li> 
    <xsl:value-of select="text()" /> 
    </li> 
</xsl:for-each> 
</ul> 
関連する問題