删除子标签并将其值连接到父标签的名称
remove child tag and concatinate its value to the name of the parent tag
可以用 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>
我想删除 <uom>
标签,并通过连接已删除的 uom 标签的值来重命名父 <REFERENCE>
标签。
所以上面会变成:
<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>
祝福
列侬
xsl:element
允许您计算结果元素的名称,例如
<xsl:template match="REFERENCE">
<xsl:element name="{local-name()}{uom}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="uom"/>
当然,基本处理将由身份转换模板完成。
可以用 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>
我想删除 <uom>
标签,并通过连接已删除的 uom 标签的值来重命名父 <REFERENCE>
标签。
所以上面会变成:
<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>
祝福
列侬
xsl:element
允许您计算结果元素的名称,例如
<xsl:template match="REFERENCE">
<xsl:element name="{local-name()}{uom}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="uom"/>
当然,基本处理将由身份转换模板完成。