Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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/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
Xml 替换xsl文件中的XPath字符串_Xml_Xslt_Xpath_Sh - Fatal编程技术网

Xml 替换xsl文件中的XPath字符串

Xml 替换xsl文件中的XPath字符串,xml,xslt,xpath,sh,Xml,Xslt,Xpath,Sh,大家好。 我需要帮助做以下事情。 我有一个带有XPath的XSL文件,它对应于一个符合UBL2.0标准的XML文件,我需要XPath来符合UBL2.1标准 需要更改的文件太多,因此我尝试使用sed命令替换每个文件中的XPath。我已尝试下一个命令: sed -i 's/select="\/ns1:Invoice\/cac:AccountingSupplierParty\/cbc:CustomerAssignedAccountID"\/>/select="\/ns1:Invoice\/cac

大家好。 我需要帮助做以下事情。 我有一个带有XPath的XSL文件,它对应于一个符合UBL2.0标准的XML文件,我需要XPath来符合UBL2.1标准

需要更改的文件太多,因此我尝试使用sed命令替换每个文件中的XPath。我已尝试下一个命令:

sed -i 's/select="\/ns1:Invoice\/cac:AccountingSupplierParty\/cbc:CustomerAssignedAccountID"\/>/select="\/ns1:Invoice\/cac:AccountingSupplierParty\/cac:Party\/cac:PartyIdentification\/cbc:ID"\/>/g' path/to/file

XPath包含需要转义的字符,因此我怀疑用命令的当前结构替换路径是否没有问题

因为XSLT本身就是XML,所以可以使用XSLT对其进行编辑。从标识转换开始,为要修改的属性添加特定模板

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

    <xsl:template match="xsl:apply-templates/@select[
      . = '/ns1:Invoice/cac:AccountingSupplierParty/cbc:CustomerAssignedAccountID'
    ]">
        <xsl:attribute name="select">
            <xsl:text>/ns1:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID</xsl:text>
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

/ns1:发票/cac:会计供应商方/cac:当事方/cac:当事方标识/cbc:标识
适用于

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output encoding="utf-8"/>

    <xsl:template match="/">
        <xsl:apply-templates select="/ns1:Invoice/cac:AccountingSupplierParty/cbc:CustomerAssignedAccountID" />
    </xsl:template>
</xsl:stylesheet>

产生

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output encoding="utf-8"/>

    <xsl:template match="/">
        <xsl:apply-templates select="/ns1:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID"/>
    </xsl:template>
</xsl:stylesheet>