2017-11-14 3 views
0

입력 :xslt는 하위 특성을 상위로 이동하고 첫 번째 줄을 제거합니다.

<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 가지고있다 주로 작업하고 원치 않는 노드와 속성을 제거했지만 그 중 일부가 나를 던지고 있습니다. Help me :(

나는 정확한 논리없는 확신으로 1,363,210
+0

을보십시오. 하위 요소에서'AttributeValue' 속성을 복사하는 것처럼 보이지만 왜'AttributeName'이 아닌지보십시오. 또한 자식 요소'UserAttribute'가 제거되었지만'MFConductorExtremityFrom'이 아닌 이유는 무엇입니까? 감사합니다 –

+0

관심을 가져 주셔서 감사합니다,이 xslt의 목표는 : AttributeValue = "xxxxxxx_02"만 <지휘자. MFConductorExtremityFrom은 더 많은 속성을 가지고 있으며 반드시 남아 있어야합니다. – aliciavika

답변

0

나는

<xsl:apply-templates select="@*|UserAttribute[last()]/@AttributeValue"/> 

또한 템플릿을 필요로 ...,

<xsl:apply-templates 
    select="@*|UserAttribute[@AttributeName='NeoWireTAG']/@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> 
+0

고마워, 대단히 감사합니다 :) – aliciavika

관련 문제