Elements and attributes
Hi Folks,
I am trying to convert an ADODB.RecordSet to a more readable form:
<rs:data>
<z:row CarVidNo="33445566" CarRegNo="345rtgy" CarMake="Renault" CarModel="Clio" CarColour="Blue" CarEngine="1.2" CarPrice="5000"/>
<z:row CarVidNo="55667788" CarRegNo="SXI 6002" CarMake="Vauxhall" CarModel="Corsa" CarColour="White" CarEngine="1.1" CarPrice="1000"/>
</rs:data>
Like So:
<z:row>
<CarVidNo>33445566</CarVidNo>
<CarRegNo>345rtgy</CarRegNo>
<CarMake>Renault</CarMake>
<CarModel>Clio</CarModel>
<CarColour>Blue</CarColour>
<CarEngine>1.2</CarEngine>
<CarPrice>5000</CarPrice>
</z:row>
However, I want to the <CarPrice> node to remain as an attribute. I know that you can convert elements to attributes etc, but is there an easier way than converting all attributes to elements and then selecting the one element you want to turn back into in an attribute.
This is the style sheet I am using at the moment:
<xsl:import href="copy.xslt"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="*[z:row]">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="s:Schema">
<xsl:for-each select="z:row">
<xsl:apply-templates />
</xsl:for-each>
</xsl:template>
<xsl:template match="z:row/@*">
<xsl:element name="{name( )}">
<xsl:value-of select="." />
</xsl:element>
</xsl:template>
<xsl:template match="z:row">
<xsl:element name="Cars">
<xsl:apply-templates select="z:row"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
And here is the copy stylesheet:
<xsl:template match="node( ) | @*">
<xsl:copy>
<xsl:apply-templates select="@* | node( )"/>
</xsl:copy>
</xsl:template>
Sorta new to this XSLT stuff, so all help is appreciated.
Cheers,
Morris
|