输入:
<Conductor Tag="A111K" Type="Normal" Length="7481" Length_Status="Real" Gauge="0.5" Wire_Type="08NtyH" Class="" Segregation="2A" TemperatureZone="20" Net="163K" Description="" Material="Undefined" MaterialType="Copper" ExternalDiameter="8.8" ProvidedWithEquipment="No" Color="BU" TagType="Standard" WireOrder="0" SourceType="Automatic" ManualAssignation="No" Resistivity="0" XDirectionLength="5497">
<UserAttribute AttributeName="NeoNetTAG" AttributeValue="blabla_018" />
<UserAttribute AttributeName="NeoWireTAG" AttributeValue="xxxxxxx_02" />
<MFConductorExtremityFrom/>
</Conductor>
输出
<Conductor AttributeValue="xxxxxxx_02" Tag="A111K" Type="Normal" Length="7481" Length_Status="Real" Gauge="0.5" Wire_Type="08NtyH" Class="" Segregation="2A" TemperatureZone="20" Net="163K" Description="" Material="Undefined" MaterialType="Copper" ExternalDiameter="8.8" ProvidedWithEquipment="No" Color="BU" TagType="Standard" WireOrder="0" SourceType="Automatic" ManualAssignation="No" Resistivity="0" XDirectionLength="5497">
<MFConductorExtremityFrom/>
</Conductor>
我尝试:XSLT但只删除两者:(
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Conductor">
<xsl:copy>
<!--
Apply the attributes of the current node and the attributes of all
following siblings (in this case, <address> and <phone>)
-->
<xsl:apply-templates select="@* | following-sibling::*/@*"/>
</xsl:copy>
</xsl:template>
<!-- Drop the <address> and <phone> elements -->
<xsl:template match="AttributeValue"/>
<!--
Identity transform: copy attributes and elements from input document to output
document as is
-->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我已经在这一段时间了 - 已经让XSLT主要工作,删除了不需要的节点和属性,但是其中有一部分让我失望。 帮帮我:(
答案 0 :(得分:0)
我认为你想要的表达是......
<xsl:apply-templates
select="@*|UserAttribute[@AttributeName='NeoWireTAG']/@AttributeValue"/>
或者也许是这样,因为我不确定你的确切逻辑......
<xsl:apply-templates select="@*|UserAttribute[last()]/@AttributeValue"/>
您还需要一个模板,然后删除UserAttribute
个节点。
<xsl:template match="UserAttribute"/>
试试这个XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="Conductor">
<xsl:copy>
<xsl:apply-templates select="@*|UserAttribute[last()]/@AttributeValue"/>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="UserAttribute"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>