Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

remove element based on values found in another element xslt-3

The following works:

<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match=
     "*[ID='579']/EMAIL"/>
    </xsl:stylesheet>

But i need to remove the email element based on many ID values
something like below is not working:

"*[ID='579|987|1023']/EMAIL"/>

How would you do it i a more cleverway with xslt-3?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use a string sequence parameter e.g.

<xsl:param name="ids" as="xs:string*" select="'579', '987', '1023'"/>

then you can use match="*[ID = $ids]/EMAIL":

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="3.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="#all">

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:param name="ids" as="xs:string*" select="'579', '987', '1023'"/>

  <xsl:template match="*[ID = $ids]/EMAIL"/>

</xsl:stylesheet>

Or pass in a single string separated with | and use match="*[ID = tokenize($ids, '\|')]/EMAIL":

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="3.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="#all">

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:param name="ids" as="xs:string" select="'579|987|1023'"/>

  <xsl:template match="*[ID = tokenize($ids, '\|')]/EMAIL"/>

</xsl:stylesheet>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading