<RowSet> <Row> <Location_Long_Desc>Sydney Office</Location_Long_Desc> <Location_Code>SYDNEY</Location_Code> <Daypart_Long_Desc>Peak Night</Daypart_Long_Desc> <Daypart_Code>PEANIG</Daypart_Code> <W_20050703_Dlr>30849.3</W_20050703_Dlr> <W_20050703_Spots>9</W_20050703_Spots> <W_20050710_Dlr>16.35</W_20050710_Dlr> <W_20050710_Spots>19</W_20050710_Spots> </Row> </RowSet>
So, I have this XML, now I need to convert the W_ nodes to the new single node. Using this XSL
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="node()"> <xsl:copy> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> <xsl:template match="*"> <xsl:variable name="tmp" select="local-name()"/> <xsl:choose> <xsl:when test="starts-with($tmp, 'W_') and ends-with($tmp, '_Dlr')"> <xsl:if test="text() != ''"> <xsl:element name="Expenditure"> <xsl:element name="Period"> <xsl:value-of select="substring($tmp,3,8)"/> </xsl:element> <xsl:element name="Value"> <xsl:apply-templates select="node()"/> </xsl:element> <xsl:element name="Spots"> <xsl:apply-templates select="//RowSet/Row/W_20050703_Spots/text()"/> </xsl:element> </xsl:element> </xsl:if> </xsl:when> <xsl:otherwise> <xsl:element name="{$tmp}"> <xsl:apply-templates select="node()"/> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
I can almost get there, but I have a couple of questions.
- I need to combine W _ ???????? Dlr and W ???????? _ Spots in separate nodes, but
- I canβt figure out how to use the variable in the xpath statement, or maybe I'm a few miles from where I should be.
Again, I still understand this, so please be careful :-)
TIA
EDIT: 12/02/2010 12:00
Good,
Another question, depending on the database level switch (which I completely forgot about), the Spots node may or may not exist.
So I still need to output, although it should not have the next class call, where the next-brother is not a valid _spots node.
Example:
<RowSet> <Row> <Location_Long_Desc>Sydney Office</Location_Long_Desc> <Location_Code>SYDNEY</Location_Code> <Daypart_Long_Desc>Peak Night</Daypart_Long_Desc> <Daypart_Code>PEANIG</Daypart_Code> <W_20050703_Dlr>30849.3</W_20050703_Dlr> <W_20050710_Dlr>16.35</W_20050710_Dlr> </Row> </RowSet>
Just to let you know, I call it all through the Oracle package
-- get the query context; v_qryctx := dbms_xmlgen.newcontext(in_sql_query); dbms_xmlgen.setnullhandling(v_qryctx, 2); dbms_xmlgen.setrowsettag(v_qryctx, 'RowSet'); dbms_xmlgen.setrowtag(v_qryctx, 'Row'); IF in_export_type = cnst_export_booking THEN dbms_xmlgen.setxslt(v_qryctx, v_booking_export_xsl); ELSIF in_export_type = cnst_export_expenditure THEN dbms_xmlgen.setxslt(v_qryctx, v_expenditure_export_xsl); END IF;