How to ignore tags ?
-
Hello, i have a semi-weird xml file to parse with xsl. The xml has an extra tag which defines what the data is below , how do i go about disregarding anything with ColName in my xsl ? XML
<?xml version="1.0" encoding="ISO-8859-1"?> <Report> <ColName> DateTime </ColName> <ColName> PointName </ColName> <ColName> PointValue </ColName> <Record> <Date> data </Date> <Name> data </Name> <Value> data </Value> </Record> <Report> <ColName> DateTime </ColName> <ColName> PointName </ColName> <ColName> PointValue </ColName> <Record> <Date> data </Date> <Name> data </Name> <Value> data </Value> </Record> <Record> <Date> data </Date> <Name> data </Name> <Value> data </Value> </Record> </Report> ``**XSL** `<?xml version="1.0"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:strip-space elements = "Report"/> <xsl:template match="Record"> <text>
</text> <xsl:text/><xsl:value-of select="normalize-space(Record)"/><xsl:text/> <xsl:value-of select="normalize-space(DateTime)"/>,<xsl:text/> <xsl:value-of select="normalize-space(PointName)"/>,<xsl:text/> <xsl:value-of select="normalize-space(PointValue)"/>,<xsl:text/> <text>
</text> <xsl:text disable-output-escaping = "yes" > </xsl:text> </xsl:template> </xsl:stylesheet>` Thanks Matt``
-
Hello, i have a semi-weird xml file to parse with xsl. The xml has an extra tag which defines what the data is below , how do i go about disregarding anything with ColName in my xsl ? XML
<?xml version="1.0" encoding="ISO-8859-1"?> <Report> <ColName> DateTime </ColName> <ColName> PointName </ColName> <ColName> PointValue </ColName> <Record> <Date> data </Date> <Name> data </Name> <Value> data </Value> </Record> <Report> <ColName> DateTime </ColName> <ColName> PointName </ColName> <ColName> PointValue </ColName> <Record> <Date> data </Date> <Name> data </Name> <Value> data </Value> </Record> <Record> <Date> data </Date> <Name> data </Name> <Value> data </Value> </Record> </Report> ``**XSL** `<?xml version="1.0"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:strip-space elements = "Report"/> <xsl:template match="Record"> <text>
</text> <xsl:text/><xsl:value-of select="normalize-space(Record)"/><xsl:text/> <xsl:value-of select="normalize-space(DateTime)"/>,<xsl:text/> <xsl:value-of select="normalize-space(PointName)"/>,<xsl:text/> <xsl:value-of select="normalize-space(PointValue)"/>,<xsl:text/> <text>
</text> <xsl:text disable-output-escaping = "yes" > </xsl:text> </xsl:template> </xsl:stylesheet>` Thanks Matt``
matty2desmara wrote:
how do i go about disregarding anything with ColName in my xsl ?
I suspect you're running foul of the default behaviour of XSL, which passes through all tags unchanged unless you say otherwise. Add a root element template that just processes what you want, like I've put in here?
<?xml version="1.0"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements = "Report"/>
<xsl:template match="/">
<xsl:apply-templates select="//Record"/>
</xsl:template>
<xsl:template match="Record">
<text> </text>
xsl:text/<xsl:value-of select="normalize-space(Record)"/>xsl:text/
<xsl:value-of select="normalize-space(DateTime)"/>,xsl:text/
<xsl:value-of select="normalize-space(PointName)"/>,xsl:text/
<xsl:value-of select="normalize-space(PointValue)"/>,xsl:text/
<text> </text>
<xsl:text disable-output-escaping = "yes" >
</xsl:text>
</xsl:template>
</xsl:stylesheet>I'm presuming the use of DateTime, PointTime and PointValue in your XSL is a typo?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p