D
David Cater
This seems like a simple task, but I'm banging my head against it.
Something about XML/XPath just isn't clicking for me yet. Here's some
sample XML:
<people>
<person name="David">
Person 1 text
<child age="13">Ruby</child>
<child age="15">Rosie</child>
</person>
<person name="Wes">
Person 2 text
<child age="5">Erin</child>
<child age="2">Rowan</child>
</person>
</people>
If I want to copy everything, I can do that with this XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xslutput method="xml" indent="yes" />
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
What if I only want to copy the nodes where person name="David"? I'm trying
to think about how the parser is processing this, and where some sort of
pattern/predicate would go, and none of my experiments to try to get that to
work are working at all.
Thanks,
David
Something about XML/XPath just isn't clicking for me yet. Here's some
sample XML:
<people>
<person name="David">
Person 1 text
<child age="13">Ruby</child>
<child age="15">Rosie</child>
</person>
<person name="Wes">
Person 2 text
<child age="5">Erin</child>
<child age="2">Rowan</child>
</person>
</people>
If I want to copy everything, I can do that with this XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xslutput method="xml" indent="yes" />
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
What if I only want to copy the nodes where person name="David"? I'm trying
to think about how the parser is processing this, and where some sort of
pattern/predicate would go, and none of my experiments to try to get that to
work are working at all.
Thanks,
David