1
<?xml version="1.0" encoding="UTF-8"?>
<MyXMLTree xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <Node1>X</Node1>
   <Node1Ext>Y</Node1Ext>
</MyXMLTree>

我想要一个 XSLT 将 XML 转换成这个

<?xml version="1.0" encoding="UTF-8"?>
<MyXMLTree xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <Node1>X</Node1>
   <Node1Ext>1</Node1Ext>
</MyXMLTree>


If Node1 == 'X' and Node1Ext != 'X' then 
    Node1Ext = '1'
else if Node1 != 'X' and Node1Ext == 'X' then 
    Node1Ext = '2'
else if Node1 == 'X'and Node1Ext =='X' then
    Node1Ext = '3'
EndIf

先感谢您 :)

4

1 回答 1

0

这应该这样做。请试一试:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="Node1Ext[. = 'X' or ../Node1 = 'X']">
    <xsl:copy>
      <xsl:value-of select="(../Node1 = 'X') + 2 * (. = 'X')"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
于 2013-08-09T16:23:53.637 回答