【问题标题】:remove child tag and concatinate its value to the name of the parent tag删除子标签并将其值连接到父标签的名称
【发布时间】:2020-05-16 09:02:53
【问题描述】:

请问可以用 XSLT 1.0 实现吗?

示例输入是

<Variable_Attributes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <Row>
        <MATNR>3006921_CAR</MATNR>
        <REFERENCE>
            <uom>EA</uom>
            <product_id>3006921_EA</product_id>
            <quantity>6</quantity>
        </REFERENCE>
    </Row>
    <Row>
        <MATNR>3006921_CAR</MATNR>
        <REFERENCE>
            <uom>CAR</uom>
            <product_id>3006921_EA</product_id>
            <quantity>6</quantity>
        </REFERENCE>
    </Row>
</Variable_Attributes>

我想删除 &lt;uom&gt; 标签,并通过连接已删除 uom 标签的值来重命名父标签 &lt;REFERENCE&gt;

所以上面会变成:

<Variable_Attributes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <Row>
        <MATNR>3006921_CAR</MATNR>
        <REFERENCE_EA>
            <product_id>3006921_EA</product_id>
            <quantity>6</quantity>
        </REFERENCE_EA>
    </Row>
    <Row>
        <MATNR>3006921_CAR</MATNR>
        <REFERENCE_CAR>
            <product_id>3006921_EA</product_id>
            <quantity>6</quantity>
        </REFERENCE_CAR>
    </Row>
</Variable_Attributes>

最好的祝福

列侬

【问题讨论】:

    标签: xml xslt transform


    【解决方案1】:

    xsl:element 允许您计算结果元素的名称,例如

    <xsl:template match="REFERENCE">
      <xsl:element name="{local-name()}{uom}">
        <xsl:apply-templates />
      </xsl:element>
    </xsl:template>
    
    <xsl:template match="uom"/>
    

    当然基础处理会通过恒等转换模板来完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-23
      • 2013-05-02
      • 2021-10-03
      • 2017-10-09
      • 2014-07-12
      相关资源
      最近更新 更多