xsl-list
[Top] [All Lists]

Re: [xsl] Help with xsl:result-document

2010-10-25 16:25:53
At 2010-10-25 22:09 +0100, Neil Owens wrote:
I've come to an impasse with trying to use xsl:result-document. I have a number of XML log files that I'm trying to extract data from and place that data into a database. I think it best to have 4 tables - OutCommand, InResponse, InCommand and OutResponse. To ease my SQL bulk import coding, I thought to produce 4 output files from one XSLT2.0 transform. However, I just can't figure out how to get result-document to work with my obvious limited knowledge of transforms. I'm looking to get 4 output files - OutCommandoutput.xml, InResponse-output.xml, InCommand-output.xml and OutResponse-output.xml. But I can't use templates, as I've more than one 'match' - and so the template tries (and obviously fails) to create another output stream to something it's already created. But I can't see a way out of this, so any advice, pointers or help will be, as ever, appreciated.

Thankfully, this has a straightforward repair.

Where you now have:

<xsl:template match="MyLog">
    <xsl:element name="Device">
        <xsl:apply-templates select="OutCommand"/>
        <xsl:apply-templates select="InResponse"/>
        <xsl:apply-templates select="InCommand"/>
        <xsl:apply-templates select="OutResponse"/>
    </xsl:element>
</xsl:template>

<xsl:template match="OutCommand">
<xsl:result-document method="xml" href="OutCommandoutput.xml">
    <OutCommand>
...
    </OutCommand>
</xsl:result-document>
</xsl:template>

<xsl:template match="InResponse">
<xsl:result-document method="xml" href="InResponse-output.xml">
    <InResponse>
...
    </InResponse>
</xsl:result-document>
</xsl:template>

<xsl:template match="InCommand">
<xsl:result-document method="xml" href="InCommand-output.xml">
    <InCommand>
...
    </InCommand>
</xsl:result-document>
</xsl:template>

<xsl:template match="OutResponse">
<xsl:result-document method="xml" href="OutResponse-output.xml">
    <OutResponse>
...
    </OutResponse>
    </xsl:result-document>
</xsl:template>


... change that to be:

<xsl:template match="MyLog">
        <xsl:result-document method="xml" href="OutCommandoutput.xml">
          <xsl:apply-templates select="OutCommand"/>
        </xsl:result-document>
        <xsl:result-document method="xml" href="InResponse-output.xml">
          <xsl:apply-templates select="InResponse"/>
        </xsl:result-document>
        <xsl:result-document method="xml" href="InCommand-output.xml">
          <xsl:apply-templates select="InCommand"/>
        </xsl:result-document>
        <xsl:result-document method="xml" href="OutResponse-output.xml">
          <xsl:apply-templates select="OutResponse"/>
        </xsl:result-document>
</xsl:template>

<xsl:template match="OutCommand">
    <OutCommand>
...
    </OutCommand>
</xsl:template>

<xsl:template match="InResponse">
    <InResponse>
...
    </InResponse>
</xsl:template>

<xsl:template match="InCommand">
    <InCommand>
...
    </InCommand>
</xsl:template>

<xsl:template match="OutResponse">
    <OutResponse>
...
    </OutResponse>
</xsl:template>


I hope this helps.

. . . . . . . . Ken

--
XSLT/XQuery training:   after http://XMLPrague.cz 2011-03-28/04-01
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--