2017-09-25 54 views
0

我有一些XML,我给了一个XSLT样式表来做一些转换,但不知何故,xsl:for-每个只能通过第一个节点循环...XSLT xsl:for-each只做第一行

我期待它循环通过所有节点和改造他们,但不知何故,只有循环槽的第一个值,我做错了什么不知道..

这是我的XML:

<?xml version="1.0"?> 
<email> 
    <uid>66</uid> 
    <subject>You have been added to a Priooo project</subject> 
    <message/> 
    <arguments> 
     <argument> 
      <name> 
       -url- 
      </name> 
      <value> 
       http://localhost/iaf4asap/#/resetpassword/c0a82001--6b0373de_15eb8270a5e_-7fea</value> 
      </argument> 
      <argument> 
       <name> 
        -inviteBy- 
       </name> 
       <value>Laurens Makel</value> 
      </argument> 
      <argument> 
       <name> 
        -project- 
       </name> 
       <value>[email protected]</value> 
      </argument> 
     </arguments> 
    <templateId> 
     c02f1e50-d569-41d9-87ec-933cded8a330 
    </templateId> 
</email> 

这是我的XSLT:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output omit-xml-declaration="yes" method="xml"/> 


    <xsl:template match="/email"> 
    <email> 
      <uniqueArguments> 
       <xsl:for-each select="arguments"> 
        <uniqueArgument> 
         <name><xsl:value-of select="argument/name"/></name> 
         <value><xsl:value-of select="argument/value"/></value> 
        </uniqueArgument> 
       </xsl:for-each> 
      </uniqueArguments> 
      <templateId> 
       <xsl:value-of select="templateId"></xsl:value-of> 
      </templateId> 
     </email> 
    </xsl:template> 

</xsl:stylesheet>  

这是给我下面的输出..:

 <?xml version="1.0"?> 
<email> 
    <uniqueArguments> 
     <uniqueArgument> 
      <name> 
       -url- 
      </name> 
      <value> 
       http://localhost/iaf4asap/#/resetpassword/c0a82001--6b0373de_15eb8270a5e_-7fea</value> 
      </uniqueArgument> 
     </uniqueArguments> 
    <templateId> 
     c02f1e50-d569-41d9-87ec-933cded8a330 
    </templateId> 
</email> 

回答

1

您在循环只有一个节点arguments,的xsl:for-每个需要在因此,许多节点的XPath,而不是使用:

<xsl:for-each select="arguments/argument">