Reputation: 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?
Upvotes: 0
Views: 63
Reputation: 167716
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>
Upvotes: 0