2012-03-23 5 views
2

私のXML文書が見えます:xslt for-eachをアトリビュートに適用するにはどうすればよいですか?私は、このような「id」属性値として、それを変換したいthis-</p> ​​ <p>は、例えば順次インクリメントされるように

<doc> 

    <system_data> 
    <registry_item id="10"> 
     <hive>HKEY_LOCAL_MACHINE</hive> 
    </registry_item> 
    <file_item id="11"> 
     <filepath>C:\Windows\System32\msasn1.dll</filepath>  
    </file_item> 
    </system_data> 

</doc> 

私は「identity」のデザインを使用していますし、私のxslはこのように見えます。

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
           xmlns:xslt="http://www.w3.org/1999/XSL/Transform"> 
<xsl:import href="Identity.xsl"/> 
<xslt:param name="newID" /> 
    <xsl:template match="//system_data/*"> 
     <xsl:for-each select="@id"> 
     <xsl:attribute name="id"> 
      <xsl:value-of select="number($newID)+1"/>  
     </xsl:attribute> 
     </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 

私はnewIDの値を "10"として渡しています。各属性を選択してその値を増やす方法は?私は、XSLを適用すると

Indentity.xslがthis-

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <!-- Whenever you match any node or any attribute --> 
    <xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

のように見える、私は次のようになっていますエラー -

An attribute node (id) cannot be created after the children of the containing element 
+0

こんにちは、あなたは同様の問題を助けることができますかhttp://stackoverflow.com/questions/12289248/xslt-attribut e-node-id-children-of-the-containingを後で作成することはできません – bouncingHippo

答えて

3

これにmatch="//system_data/*"のためにテンプレートを変更してみてください:

<xsl:template match="@id"> 
    <xsl:attribute name="id"> 
     <xsl:value-of select="number($newID)+count(preceding::*/@id)"/> 
    </xsl:attribute> 
    </xsl:template> 
+0

ありがとう!それはかなりうまくいく。 – user837208

+0

@ user837208 - あなたは大歓迎です! –

+0

あなたも同様の問題を解決できますか?http://stackoverflow.com/questions/12289248/xslt-attribute-node-id-cannot-be-created-after-the-children-of-the- containing – bouncingHippo

関連する問題