[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XML to XML transformation

Subject: Re: XML to XML transformation
From: "Simon Kelly" <kelly@xxxxxxxxxx>
Date: Tue, 15 Apr 2003 09:50:27 +0200
timestamp transform
Cheers for that Mike, it will be most useful.

Here is the more complex structure I want to create (data from source in the
[]).

<!-- <mdatas>
    <label>[from external reference]</label>
    <starttime>[ROWSET/first-child()/TIMESTAMP</starttime>
    <endtime>[ROWSET/last-child()/TIMESTAMP</endtime>
    [for-each-child() of ROWSET]
        <mdata>
            [if first-child()]
                <timestamp>[TIMESTAMP]</timestamp>
            [end-if]
            [for-each-child() && not(first-child())]
                <svalue>
                    <label>[local-name()]</label>
                    <value>[text()]</value>
                </svalue>
            [end-for]
        </mdata>
    [end-for]
</mdatas> -->

Since my last post I have created a xsl to do this (I think, as I can'T get
it to run yet from other bugs) but I'm not sure if I am using xsl correctly
to produce a Document rather than text.  It looks ok to me, but does seem a
little shoddy, but here it is:

"<xsl:stylesheet version="1.0"
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"
"<xsl:output method="text"/>"
"<xsl:template match="/">"
"  <slowcontrol>"
"    <xsl:apply-templates />"
"  </slowcontrol>"
"</xsl:template>"
"<xsl:template match="ROWSET">"
"  <measuringdatasequence>"
"    <label>fp1v1</label>"
"    <xsl:for-each select="ROW">"
"      <xsl:choose>"
"        <xsl:when test="position() = 1">"
"          <starttime><xsl:value-of select="./TIMESTAMP/text()"
/></starttime>"
"        </xsl:when>"
"        <xsl:when test="position() = last()">"
"          <endtime><xsl:value-of select="./TIMESTAMP/text()" /></endtime>"
"        </xsl:when>"
"        <xsl:otherwise />"
"      </xsl:choose>"
"    </xsl:for-each>"
"    <xsl:apply-templates />"
"  </measuringdatasequence>"
"</xsl:template>"
"<xsl:template match="ROW">"
"  <measuringdata>"
"  <xsl:for-each select="*">"
"    <xsl:choose>"
"      <xsl:when test="string(local-name())=string('TIMESTAMP')">"
"        <timestamp><xsl:value-of select="./text()" /></timestamp>"
"      </xsl:when>"
"      <xsl:otherwise>"
"        <sensorvalue>"
"          <label><xsl:value-of select="local-name()" /></label>"
"          <value><xsl:value-of select="./text()" /></value>"
"        </sensorvalue>"
"      </xsl:otherwise>"
"    </xsl:choose>"
"  </xsl:for-each>"
"</xsl:template>"
"</xsl:stylesheet>"

Any help would be most appriciated.

Kind regards

Simon

----- Original Message -----
From: "Mike Brown" <mike@xxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, April 14, 2003 9:29 PM
Subject: Re:  XML to XML transformation


> Simon Kelly wrote:
> > I have been looking throught the xslt-cookbook to try to work out the
best
> > was of turning an flat XML document, in to quite a deep complex
document.
> > But I am having a couple of problems working out what it the best way of
> > doing this in xsl.
> >
> > The flat structure is an output from a relational db, using ROWSET, ROW
then
> > $column-name as the child node identifiers.
>
> You mean you have something like this?
>
> <DATA>
>   <ROWSET>
>     <ROW>
>       <Id>123</Id>
>       <GivenName>Jane</GivenName>
>       <FamilyName>Doe</FamilyName>
>     </ROW>
>     ...
>   </ROWSET>
>   ...
> </DATA>
>
> What's your definition of deep and complex, i.e. what is an example of the
> XML you want in your output, given the above input?
>
> > However, I will be keeping none of the node names in the new structure,
> > and I want xsl to create a new document and not a string output.
> > I am using the javax.xml.transform.Transformer.
>
> In XSLT, you create a new document in the form of an XPath node tree that
is
> similar to a DOM Document object. Typically, this "result tree" is
serialized
> as an encoded string after construction, but different XSLT processors
offer
> alternative types of output, including DOM Document objects. Processors
that
> implement JAXP may support the DOMResult class, which you can create an
> instance of to be the destination for the result tree. You pass this
instance
> as the second argument to the Transformer's transform() method. Read more
about
> DOMResult in the javax.xml.transform docs. Your XSLT processor probably
comes
> with examples demonstrating its usage.
>
> When constructing the new result tree, you are free to create any nodes
you
> want, and to traverse any part of the source tree, starting at the root
node.
> Your new elements and attributes can be given any names you want; there's
no
> obligation to copy the input, or to even base anything on the input at
all.
>
> > I also need the transform to be very quick, as the relational document
size
> > can be in excess of 4MB.
>
> This will be more of a problem. Very large input files are difficult to
> process because some nuances of XSLT require that the document be cached
and
> operated on with the entire document being in memory at once. There are
> various ideas for working around this, including using a SAX parser to
break
> the document into chunks that the XSLT processor can handle more quickly
(and
> then you have to collect and reassemble the output yourself),
vendor-specific
> extension functions such as saxon:preview (but only in limited
situations),
> and using SAX-based transformation approaches such as STX. See also
> http://www.biglist.com/lists/xsl-list/archives/200301/msg00804.html
>
> Mike
>
> --
>   Mike J. Brown   |  http://skew.org/~mike/resume/
>   Denver, CO, USA |  http://skew.org/xml/
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.