July 31, 2007 at 8:37 am
hi
can somebody help me out in getting the column headers through xsl file
fro example i have a following xsl file below is my xsl file
<?xml version="1.0"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="stateTotal">
<xsl:value-of select="normalize-space(./state)"/><xsl:text>;</xsl:text>
<xsl:value-of select="normalize-space(./cTotal)"/><xsl:text>;</xsl:text>
<xsl:value-of select="normalize-space(./eTotal)"/><xsl:text>;</xsl:text>
<xsl:value-of select="normalize-space(./Total)"/><xsl:text>;</xsl:text>
</xsl:template>
</xsl:stylesheet>
and i would expect the output to be with the column names on the top
the above xsl is working fine but not getting the column headers
July 31, 2007 at 10:08 am
What's the final outcome that you are trying to achieve? I can't understand why you'd need to do this on a stylesheet?
It's a tricky one with xsl. You can't have a colon ( : ) in the tag name when using OPENXML so the first thing to do is replace the colons with an allowable character (for example '_').
You can then start to use OPENXML to return attribute and element details.
DECLARE @idoc int
DECLARE @doc varchar(2000)
SET @doc ='
<?xml version="1.0"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="stateTotal">
<xsl:value-of select="normalize-space(./state)"/><xsl:text>;</xsl:text>
<xsl:value-of select="normalize-space(./cTotal)"/><xsl:text>;</xsl:text>
<xsl:value-of select="normalize-space(./eTotal)"/><xsl:text>;</xsl:text>
<xsl:value-of select="normalize-space(./Total)"/><xsl:text>;</xsl:text>
</xsl:template>
</xsl:stylesheet>
'
SELECT @doc = REPLACE(@doc, ':', '_')
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
SELECT colName
FROM OPENXML (@idoc, '/xsl_stylesheet/xsl_template/xsl_value-of', 1)
WITH ( colName varchar(100) '@select')
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply