Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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
Xslt 复制期间从XSL转换的XML缺少属性_Xslt - Fatal编程技术网

Xslt 复制期间从XSL转换的XML缺少属性

Xslt 复制期间从XSL转换的XML缺少属性,xslt,Xslt,我在我们的项目中有一个XSL。我正在更新,以满足新的需求。 我在文章中复制了其中的一部分(XSL相当大,大约有1200行)。 在下面的xml中,我在InvoiceDetailRequest/InvoiceDetailRequestHeader/Exterinsic/Attachment/URL元素下有一个值。 通过使用下面的xsl,我将值“URL”更新为“更新的URL”。 但是在Output XML中,它没有复制属性name=“invoicePDF”。 谁能帮我解释一下为什么属性没有复制 谢谢你

我在我们的项目中有一个XSL。我正在更新,以满足新的需求。 我在文章中复制了其中的一部分(XSL相当大,大约有1200行)。 在下面的xml中,我在InvoiceDetailRequest/InvoiceDetailRequestHeader/Exterinsic/Attachment/URL元素下有一个值。 通过使用下面的xsl,我将值“URL”更新为“更新的URL”。 但是在Output XML中,它没有复制属性name=“invoicePDF”。 谁能帮我解释一下为什么属性没有复制

谢谢你的帮助

基蒂

-------------------输入XML-----------------

<xsl:output omit-xml-declaration="yes" encoding="UTF-8"
    indent="yes" />
<xsl:strip-space elements="*" />

<xsl:variable name="invoicePDFExtrinsic"
    select="InvoiceDetailRequest/InvoiceDetailRequestHeader/Extrinsic[@name='invoicePDF']" />

<xsl:template match="@*|node()">   <!-- Whenever any node or any attribute is matched -->
    <xsl:copy>     <!-- Copy the current node -->
        <xsl:apply-templates select="@*|node()" />  <!-- Including any attributes it has and any child nodes -->
    </xsl:copy>
</xsl:template>

<xsl:template match="InvoiceDetailRequest/InvoiceDetailRequestHeader">
    <xsl:copy>
        <!-- And everything inside it -->
        <xsl:apply-templates select="@* | *" />

        <xsl:if test="not($invoicePDFExtrinsic)">
            <xsl:element name="Extrinsic">
                <xsl:attribute name="name">invoicePDF</xsl:attribute>
                <Attachment>
                    <URL>
                        URL
                    </URL>
                </Attachment>
            </xsl:element>
        </xsl:if>
    </xsl:copy>

</xsl:template>

<xsl:template
    match="InvoiceDetailRequest/InvoiceDetailRequestHeader/Extrinsic[@name='invoicePDF']">
    <xsl:copy>
        <xsl:choose>
            <xsl:when test="$invoicePDFExtrinsic">
            <Attachment>
                    <URL>
                        Updated URL
                    </URL>
                </Attachment>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="@*|node()" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:copy>
</xsl:template>
<InvoiceDetailRequest>
    <InvoiceDetailRequestHeader>
        <Extrinsic>
            <Attachment>
                <URL>
                    Updated URL
                </URL>
            </Attachment>
        </Extrinsic>
    </InvoiceDetailRequestHeader>
</InvoiceDetailRequest>

统一资源定位地址
----------------XSL---------------------

<xsl:output omit-xml-declaration="yes" encoding="UTF-8"
    indent="yes" />
<xsl:strip-space elements="*" />

<xsl:variable name="invoicePDFExtrinsic"
    select="InvoiceDetailRequest/InvoiceDetailRequestHeader/Extrinsic[@name='invoicePDF']" />

<xsl:template match="@*|node()">   <!-- Whenever any node or any attribute is matched -->
    <xsl:copy>     <!-- Copy the current node -->
        <xsl:apply-templates select="@*|node()" />  <!-- Including any attributes it has and any child nodes -->
    </xsl:copy>
</xsl:template>

<xsl:template match="InvoiceDetailRequest/InvoiceDetailRequestHeader">
    <xsl:copy>
        <!-- And everything inside it -->
        <xsl:apply-templates select="@* | *" />

        <xsl:if test="not($invoicePDFExtrinsic)">
            <xsl:element name="Extrinsic">
                <xsl:attribute name="name">invoicePDF</xsl:attribute>
                <Attachment>
                    <URL>
                        URL
                    </URL>
                </Attachment>
            </xsl:element>
        </xsl:if>
    </xsl:copy>

</xsl:template>

<xsl:template
    match="InvoiceDetailRequest/InvoiceDetailRequestHeader/Extrinsic[@name='invoicePDF']">
    <xsl:copy>
        <xsl:choose>
            <xsl:when test="$invoicePDFExtrinsic">
            <Attachment>
                    <URL>
                        Updated URL
                    </URL>
                </Attachment>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="@*|node()" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:copy>
</xsl:template>
<InvoiceDetailRequest>
    <InvoiceDetailRequestHeader>
        <Extrinsic>
            <Attachment>
                <URL>
                    Updated URL
                </URL>
            </Attachment>
        </Extrinsic>
    </InvoiceDetailRequestHeader>
</InvoiceDetailRequest>


发票PDF
统一资源定位地址
更新的URL

--------------------输出XML-------------------------------------------------------

<xsl:output omit-xml-declaration="yes" encoding="UTF-8"
    indent="yes" />
<xsl:strip-space elements="*" />

<xsl:variable name="invoicePDFExtrinsic"
    select="InvoiceDetailRequest/InvoiceDetailRequestHeader/Extrinsic[@name='invoicePDF']" />

<xsl:template match="@*|node()">   <!-- Whenever any node or any attribute is matched -->
    <xsl:copy>     <!-- Copy the current node -->
        <xsl:apply-templates select="@*|node()" />  <!-- Including any attributes it has and any child nodes -->
    </xsl:copy>
</xsl:template>

<xsl:template match="InvoiceDetailRequest/InvoiceDetailRequestHeader">
    <xsl:copy>
        <!-- And everything inside it -->
        <xsl:apply-templates select="@* | *" />

        <xsl:if test="not($invoicePDFExtrinsic)">
            <xsl:element name="Extrinsic">
                <xsl:attribute name="name">invoicePDF</xsl:attribute>
                <Attachment>
                    <URL>
                        URL
                    </URL>
                </Attachment>
            </xsl:element>
        </xsl:if>
    </xsl:copy>

</xsl:template>

<xsl:template
    match="InvoiceDetailRequest/InvoiceDetailRequestHeader/Extrinsic[@name='invoicePDF']">
    <xsl:copy>
        <xsl:choose>
            <xsl:when test="$invoicePDFExtrinsic">
            <Attachment>
                    <URL>
                        Updated URL
                    </URL>
                </Attachment>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="@*|node()" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:copy>
</xsl:template>
<InvoiceDetailRequest>
    <InvoiceDetailRequestHeader>
        <Extrinsic>
            <Attachment>
                <URL>
                    Updated URL
                </URL>
            </Attachment>
        </Extrinsic>
    </InvoiceDetailRequestHeader>
</InvoiceDetailRequest>

更新的URL


如果您想在任何情况下复制属性,则至少要更改

<xsl:template
    match="InvoiceDetailRequest/InvoiceDetailRequestHeader/Extrinsic[@name='invoicePDF']">
    <xsl:copy>


由于您只想操作
URL
元素,因此为该元素编写模板可能比您所采用的方法更容易