0

I have this XML file, I need to remove ContentText element with the attribute languageCode="FR", if the ContentText element with the attribute languageCode="EN" exist else keep the French text.

Current XML :

<MaterialByElementsResponse_sync>
  <Material>
    <Detail>
        <ContentText languageCode="FR">Inscription</ContentText>
        <ContentText languageCode="EN">Subscription</ContentText>
    </Detail>  
  </Material>   
</MaterialByElementsResponse_sync>

Desired Output :

<MaterialByElementsResponse_sync>
  <Material>
    <Detail>
        <ContentText languageCode="EN">Subscription</ContentText>
    </Detail>  
  </Material>   
</MaterialByElementsResponse_sync>

I tried this XSLT but it is always deleting the FR text even if the EN text doesn't exist :

  <xsl:template match="node()|@*">

    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>

  </xsl:template>
  <xsl:template match="ContentText[@languageCode='FR']"/>
 </xsl:stylesheet>

Remember if there is no English text, the French text shouldn't be removed.

Thank you very much.

1
  • I added my current XSLT to main topic. You can take a look. Thank you. Commented Jun 10, 2016 at 13:45

1 Answer 1

2

Change:

<xsl:template match="ContentText[@languageCode='FR']"/>

to:

<xsl:template match="ContentText[@languageCode='FR'][../ContentText[@languageCode='EN']]"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.