Hi All,
given the source document:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<child>
<test id="1" name="first child"/>
</child>
<child>
<test id="2" name="second child"/>
</child>
<child>
<test id="3" name="third child"/>
</child>
</root>
I would suppress the the child elements that contain a test element with the value of the id attribute in a list of known ids; for instance, assuming that the list of ids to remove is {1,3}, I would obtain the document:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<child>
<test id="2" name="second child"/>
</child>
</root>
where only the second child element is retained.
I'm only able to suppress a single child element using the following XSL transform;
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" <xsl
utput method="xml" indent="yes" /> <xsl:template match="@*|node"> <xsl:copy> <xsl:apply-templates select="@*|node"/> </xsl:copy> </xsl:template> <xsl:template match="child[test[@id='1']]"/> </xsl:stylesheet>
Is it possible to match and suppress multiple child elements whose ids are contained in a given list ?
Since I'm invoking the transform from Java, I would like to set a template parameter to the list of ids to be removed; e.g. as comma delimited list, and write the last match condition as something like this:
....
<xsl
aram name="idToRemove" select="default" />
<xsl:template match="child[test[@id in $idsToRemove]]"/> ....
Note that I'm using XSLT 1.0, so I cannot leverage the enhancements of XSLT 2.0, but I'm wondering if there is some trick to do the job; for instance injecting the list of ids to remove into the same XSLT document and then iterating over them and suppressing any matching child element from the source document... maybe something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:data="http://sample.array.parameters/data" version="1.0"> <xsl
utput method="xml" indent="yes" /> <data
arameters> <id>1</id> <id>3</id> </data
arameters> <xsl:variable name="parameters-root" select="document('')/*/data
arameters"/> <xsl:template match="@*|node"> <xsl:copy> <xsl:apply-templates select="@*|node"/> </xsl:copy> </xsl:template> <xsl:template match="child[test[@id in $parameters-root]]"/> </xsl:stylesheet>
Thanks a lot for any suggestion
Regards,
Patrizio
given the source document:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<child>
<test id="1" name="first child"/>
</child>
<child>
<test id="2" name="second child"/>
</child>
<child>
<test id="3" name="third child"/>
</child>
</root>
I would suppress the the child elements that contain a test element with the value of the id attribute in a list of known ids; for instance, assuming that the list of ids to remove is {1,3}, I would obtain the document:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<child>
<test id="2" name="second child"/>
</child>
</root>
where only the second child element is retained.
I'm only able to suppress a single child element using the following XSL transform;
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" <xsl
Is it possible to match and suppress multiple child elements whose ids are contained in a given list ?
Since I'm invoking the transform from Java, I would like to set a template parameter to the list of ids to be removed; e.g. as comma delimited list, and write the last match condition as something like this:
....
<xsl
<xsl:template match="child[test[@id in $idsToRemove]]"/> ....
Note that I'm using XSLT 1.0, so I cannot leverage the enhancements of XSLT 2.0, but I'm wondering if there is some trick to do the job; for instance injecting the list of ids to remove into the same XSLT document and then iterating over them and suppressing any matching child element from the source document... maybe something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:data="http://sample.array.parameters/data" version="1.0"> <xsl
Thanks a lot for any suggestion
Regards,
Patrizio