Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 替换节的XSLT_Xml_Xslt - Fatal编程技术网

Xml 替换节的XSLT

Xml 替换节的XSLT,xml,xslt,Xml,Xslt,我试图用XSLT替换XML中的一个部分 输入: <data> <entry> <id>1</id> <propertyA>10</propertyA> <propertyB>20</propertyB> </entry> <entry> <id>2</id> &

我试图用XSLT替换XML中的一个部分

输入:

<data>
    <entry>
       <id>1</id>
       <propertyA>10</propertyA>
       <propertyB>20</propertyB>
    </entry>
    <entry>
       <id>2</id>
       <propertyA>8</propertyA>
       <propertyB>12</propertyB>
    </entry>
</data>
<data>
    <entry>
       <id>1</id>
       <propertyA>15</propertyA>
       <propertyB>8</propertyB>
    </entry>
    <entry>
       <id>2</id>
       <propertyA>8</propertyA>
       <propertyB>12</propertyB>
    </entry>
</data>

输出中缺少
条目
元素,因为您没有将其复制到输出中。此外,在满足“何时”条件的情况下:

<xsl:when test="id=$replaceId"></xsl:when>
输出

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:output method="xml" indent="yes"/>

    <xsl:variable name="replaceID" select="'2'"/>

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

   <xsl:template match="propertyA[parent::entry/id = $replaceID]">
        <xsl:copy>
            <xsl:value-of select="15"/>
        </xsl:copy>
   </xsl:template>

   <xsl:template match="propertyB[parent::entry/id = $replaceID]">
        <xsl:copy>
            <xsl:value-of select="8"/>
        </xsl:copy>
   </xsl:template>

</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<data>
    <entry>
       <id>1</id>
       <propertyA>15</propertyA>
       <propertyB>8</propertyB>
    </entry>
    <entry>
       <id>2</id>
       <propertyA>8</propertyA>
       <propertyB>12</propertyB>
    </entry>
</data>

1.
15
8.
2.
8.
12
<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:output method="xml" indent="yes"/>

    <xsl:variable name="replaceID" select="'2'"/>

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

   <xsl:template match="propertyA[parent::entry/id = $replaceID]">
        <xsl:copy>
            <xsl:value-of select="15"/>
        </xsl:copy>
   </xsl:template>

   <xsl:template match="propertyB[parent::entry/id = $replaceID]">
        <xsl:copy>
            <xsl:value-of select="8"/>
        </xsl:copy>
   </xsl:template>

</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<data>
    <entry>
       <id>1</id>
       <propertyA>15</propertyA>
       <propertyB>8</propertyB>
    </entry>
    <entry>
       <id>2</id>
       <propertyA>8</propertyA>
       <propertyB>12</propertyB>
    </entry>
</data>