鑑於這種XML ...如何使用沒有空白和標籤編碼的XSLT將節點集複製到結果屬性中?
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item>
<this>
<that>one</that>
</this>
</item>
<item>
<this>
<that>two</that>
</this>
</item>
<item>
<this>
<that>three</that>
</this>
</item>
</root>
我想要做的項目複製到一個新的格式,它看起來像......
<new>
<parm x=">that<one>/that<"/>
<parm x=">that<two>/that<"/>
<parm x=">that<three>/that<"/>
</new>
樣式表...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="feedKey"/>
<xsl:template match="/">
<new>
<xsl:apply-templates select="//item"/>
</new>
</xsl:template>
<xsl:template match="item">
<xsl:element name="param">
<xsl:attribute name="x"><xsl:copy-of select="node()"/></xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
...產生...
<?xml version="1.0" encoding="UTF-8"?>
<new>
<param x="
 
one
 
 "/>
<param x="
 
two
 
 "/>
<param x="
 
three
 
 "/>
</new>
簡單地更改紙張要移除的屬性...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="feedKey"/>
<xsl:template match="/">
<new>
<xsl:apply-templates select="//item"/>
</new>
</xsl:template>
<xsl:template match="item">
<xsl:element name="param">
<xsl:copy-of select="node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
... ...產生
<?xml version="1.0" encoding="UTF-8"?>
<new>
<param>
<this>
<that>one</that>
</this>
</param>
<param>
<this>
<that>two</that>
</this>
</param>
<param>
<this>
<that>three</that>
</this>
</param>
</new>
我怎麼能轉換「這個」入屬性「X」與空白區域被剝離並且標籤被編碼?
好問題(+1)。見我的回答對一個完整的解決方案。 :) – 2010-06-09 19:35:32