E
elora_c
I'm trying to write XSLT that will filter out an XML based on an
attribute's value. XML looks like:
<postings>
<channel name="A">
<posting Connected="True" name="Posting1" />
<posting Connected="False" name="Posting2" />
</channel>
<channel name="B">
<channel name="C">
<posting Connected="True" name="Posting3" />
</channel>
</channel>
</postings>
Output should look like:
<postings>
<posting Connected="True" name="Posting1" />
<posting Connected="True" name="Posting3" />
</postings>
So, I'm trying to extract all nodes that have the attribute value
Connected="True." Any node that doesn't have the Connected attribute,
or whose value isn't True should be ignored. I can filter out those
nodes whose value isn't True, but that still leaves the Channel nodes
that don't have the attribute. And when I try to explicitly filter out
the Channel nodes, nothing gets processed since the posting nodes are
children of Channel nodes. If it helps, Channel nodes will never have
the Connected attribute and Posting nodes always will.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2004/10/xpath-functions"
xmlns:xdt="http://www.w3.org/2004/10/xpath-datatypes">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//*[@Connected='False']">
</xsl:template>
</xsl:stylesheet>
Can anyone help?
Thanks,
Carole
attribute's value. XML looks like:
<postings>
<channel name="A">
<posting Connected="True" name="Posting1" />
<posting Connected="False" name="Posting2" />
</channel>
<channel name="B">
<channel name="C">
<posting Connected="True" name="Posting3" />
</channel>
</channel>
</postings>
Output should look like:
<postings>
<posting Connected="True" name="Posting1" />
<posting Connected="True" name="Posting3" />
</postings>
So, I'm trying to extract all nodes that have the attribute value
Connected="True." Any node that doesn't have the Connected attribute,
or whose value isn't True should be ignored. I can filter out those
nodes whose value isn't True, but that still leaves the Channel nodes
that don't have the attribute. And when I try to explicitly filter out
the Channel nodes, nothing gets processed since the posting nodes are
children of Channel nodes. If it helps, Channel nodes will never have
the Connected attribute and Posting nodes always will.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2004/10/xpath-functions"
xmlns:xdt="http://www.w3.org/2004/10/xpath-datatypes">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//*[@Connected='False']">
</xsl:template>
</xsl:stylesheet>
Can anyone help?
Thanks,
Carole