2011-08-18 54 views
0

我要插入從子元件PCDATA到選擇的節點屬性插入PCDATA成屬性

XML

<root> 
    <tag> 
    <tag1>SOME TEXT</tag1> 
    </tag> 
</root> 

MY XSL

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

    <xsl:template match="root"> 
     <tag-out> 
      <xsl:attribute name="text"> 
       <!-- What should I select? --> 
       <xsl:value-of select="tag/tag1/???"/> 
      </xsl:attribute> 
     <tag-out> 
    </xsl:template> 

    ........... 

</xsl:stylesheet> 

希望的輸出XML

<root-out text="SOME TEXT"> 
    <tag-out/> 
</root-out> 

感謝

回答

2

出了什麼問題簡單地做

<tag-out text="{tag/tag1}"></tag-out> 

?當然你的樣品有

<tag-out> 
     <xsl:attribute name="text"> 

      <xsl:value-of select="tag/tag1"/> 
     </xsl:attribute> 
    <tag-out> 

也是可以的。但隨着你的帖子標記XSLT 2.0我至少做

<tag-out> 
     <xsl:attribute name="text" select="tag/tag1"/> 
    <tag-out> 

如果你真的需要xsl:attribute

+0

對不起,我寫了一個 :)的例子,並在我的主腳本中出現錯誤。問題解決了 – Nawa