Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Match an attribute value in a set of possible values

From: "patrin" <patrizio.trinchini@----------.--->
To: NULL
Date: 9/1/2006 6:31:00 AM

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:output 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:param 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:output method="xml" indent="yes" />
	<data:parameters>
		<id>1</id>
		<id>3</id>
	</data:parameters>
	<xsl:variable name="parameters-root"
select="document('')/*/data:parameters"/>
	<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



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent