XPATH 1.0 construct a new xml document out of original one depending on condition -
i have xml document one:
<datacontainerlist> <container> <localdatacontainer> <file>inputfile3</file> </localdatacontainer> </container> <container> <localdatacontainer> <file>inputfile2</file> </localdatacontainer> </container> <container> <localdatacontainer> <file>inputfile3</file> </localdatacontainer> </container> </datacontainerlist>
and want filter out container file name = inputfile3
means: want create new datacontainerelist first , third container.
is possible 1 xpath1.0
command? cannot use xsl
or something, plain xpath
, should work arbitrary datacontainerlist.
from description, sounds rather filter out containers
named "inputfile3", want select such containers.
you can use simple variation of identity transformation in xslt copy output except containers
not named "inputfile3".
this input xml:
<?xml version="1.0" encoding="utf-8"?> <containers> <container> <localdatacontainer> <file>inputfile3</file> </localdatacontainer> </container> <container> <localdatacontainer> <file>inputfile2</file> </localdatacontainer> </container> <container> <localdatacontainer> <file>inputfile3</file> </localdatacontainer> </container> </containers>
applied xslt:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="container[localdatacontainer/file != 'inputfile3']"/> </xsl:stylesheet>
would yield output xml:
<?xml version="1.0" encoding="utf-8"?> <containers> <container> <localdatacontainer> <file>inputfile3</file> </localdatacontainer> </container> <container> <localdatacontainer> <file>inputfile3</file> </localdatacontainer> </container> </containers>
Comments
Post a Comment