XML to XML XSLT Transform

Post Reply
User avatar
vernonvd
Member
Posts: 38
Joined: Tue Oct 09, 2012 9:21 am
Location: Pretoria, South Africa

XML to XML XSLT Transform

Post by vernonvd »

XSLT help please

i want to combine the element in to one line.

original xml

<?xml version="1.0" encoding="UTF-8"?>
<Log>
<SQLStatementValue>
<Row>
<Column Name="SOID" DataType="INTEGER">123</Column>
<Column Name="REFERENCE" DataType="BINARY">Test1</Column>
<Column Name="CUSORDERNO" DataType="BINARY">Order1</Column>
</Row>
<Row>
<Column Name="SOID" DataType="INTEGER">456</Column>
<Column Name="REFERENCE" DataType="BINARY">Test2</Column>
<Column Name="CUSORDERNO" DataType="BINARY">Order2</Column>
</Row>

</SQLStatementValue>
</Log>

the result i want, hopefully this is possible.

<Log>
<SQLStatementValue>
<Row>
<Column Name="SOID" DataType="INTEGER">123 Test1 Order1</Column>
</Row>
<Row>
<Column Name="SOID" DataType="INTEGER">456 Test2 Order2</Column>
</Row>

</SQLStatementValue>
</Log>
User avatar
vernonvd
Member
Posts: 38
Joined: Tue Oct 09, 2012 9:21 am
Location: Pretoria, South Africa

Re: XML to XML XSLT Transform

Post by vernonvd »

Ok, with the help of google and a lot of testing i managed to get a working XSLT for this. :D

Code: Select all

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Row">
        <info><xsl:apply-templates/></info>
    </xsl:template>

    <xsl:template match="Row/*">
        <xsl:if test="not(position()=1)">
            <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:value-of select="."/>
    </xsl:template>

</xsl:stylesheet>
Post Reply