|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
XML data transformation problemHello,
I get strange results with the saxon API with the following XML data transformation : I have input files including data as follow : <root> <row name="r1" idMin="0" idMax="20"></row> <row name="r2" idMin="0" idMax="1"></row> </root> I would like to transform this input into the following wanted output : <root> <row name="r1" id="0"/> <row name="r1" id="1"/> <row name="r1" id="2"/> <row name="r1" id="3"/> <row name="r1" id="4"/> <row name="r1" id="5"/> <row name="r1" id="6"/> <row name="r1" id="7"/> <row name="r1" id="8"/> <row name="r1" id="9"/> <row name="r1" id="10"/> <row name="r1" id="11"/> <row name="r1" id="12"/> <row name="r1" id="13"/> <row name="r1" id="14"/> <row name="r1" id="15"/> <row name="r1" id="16"/> <row name="r1" id="17"/> <row name="r1" id="18"/> <row name="r1" id="19"/> <row name="r1" id="20"/> <row name="r2" id="0"/> <row name="r2" id="1"/> </root> I tried this transformation with the following xsl file (slightly modified but mainly constructed thanks to a Jeni Tennison mail : http://www.biglist.com/lists/xsl-list/archives/200104/msg00869.html) <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes" method="xml" media-type="text/xml; charset=UTF-8"/> <xsl:variable name="random-nodes" select="document('')//*" /> <xsl:template match="root"> <xsl:element name="root"> <xsl:apply-templates /> </xsl:element> </xsl:template> <xsl:template match="root/row"> <xsl:variable name="name" select="@name" /> <xsl:variable name="min" select="@idMin" /> <xsl:variable name="nnodes" select="(@idMax - @idMin) + 1" /> <xsl:for-each select="$random-nodes[position() <= $nnodes]"> <row> <xsl:attribute name="name"> <xsl:value-of select="$name" /> </xsl:attribute> <xsl:attribute name="id"> <xsl:value-of select="position() + $min - 1" /> </xsl:attribute> </row> </xsl:for-each> </xsl:template> </xsl:stylesheet> but I only got the following output : # java -jar "d:\Software\Saxon\saxon9.jar" -t -s:in2.xml -xsl:in2.xsl -o:out2.xml Saxon 9.1.0.7J from Saxonica Java version 1.6.0 Warning: at xsl:stylesheet on line 2 column 80 of in2.xsl: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor Stylesheet compilation time: 406 milliseconds Processing file:/D:/in2.xml Building tree for file:/D:/in2.xml using class net.sf.saxon.tinytree.TinyBuilder Tree built in 0 milliseconds Tree size: 8 nodes, 0 characters, 6 attributes Loading net.sf.saxon.event.MessageEmitter Building tree for file:/D:/in2.xsl using class net.sf.saxon.tinytree.TinyBuilder Tree built in 0 milliseconds Tree size: 41 nodes, 0 characters, 20 attributes Execution time: 78 milliseconds Memory used: 945440 NamePool contents: 17 entries in 17 chains. 6 prefixes, 6 URIs <?xml version="1.0" encoding="UTF-8"?> <root> <row name="r1" id="0"/> <row name="r1" id="1"/> <row name="r1" id="2"/> <row name="r1" id="3"/> <row name="r1" id="4"/> <row name="r1" id="5"/> <row name="r1" id="6"/> <row name="r1" id="7"/> <row name="r1" id="8"/> <row name="r1" id="9"/> <row name="r1" id="10"/> <row name="r1" id="11"/> <row name="r1" id="12"/> <row name="r1" id="13"/> <row name="r1" id="14"/> <row name="r1" id="15"/> <row name="r2" id="0"/> <row name="r2" id="1"/> </root> As you can see above "r1" id values from 16 to 20 are mysteriously missing in the actual output... Is this a bug with saxon or do you see something wrong somewhere else ? Thanks in advanced for your answers, Best regards, Damien, ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@... https://lists.sourceforge.net/lists/listinfo/saxon-help |
|
|
Re: XML data transformation problemDamien BOUCHET wrote:
> I tried this transformation with the following xsl file (slightly > modified but mainly constructed thanks to a Jeni Tennison mail : > http://www.biglist.com/lists/xsl-list/archives/200104/msg00869.html) > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > <xsl:output indent="yes" method="xml" media-type="text/xml; > charset=UTF-8"/> > <xsl:variable name="random-nodes" select="document('')//*" /> > > <xsl:template match="root"> > <xsl:element name="root"> > <xsl:apply-templates /> > </xsl:element> > </xsl:template> > > <xsl:template match="root/row"> > <xsl:variable name="name" select="@name" /> > <xsl:variable name="min" select="@idMin" /> > <xsl:variable name="nnodes" select="(@idMax - @idMin) + 1" /> > <xsl:for-each select="$random-nodes[position() <= $nnodes]"> > <row> > but I only got the following output : > > # java -jar "d:\Software\Saxon\saxon9.jar" -t -s:in2.xml -xsl:in2.xsl > -o:out2.xml > Saxon 9.1.0.7J from Saxonica > Java version 1.6.0 > Warning: at xsl:stylesheet on line 2 column 80 of in2.xsl: > Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor > Stylesheet compilation time: 406 milliseconds > Processing file:/D:/in2.xml > Building tree for file:/D:/in2.xml using class > net.sf.saxon.tinytree.TinyBuilder > Tree built in 0 milliseconds > Tree size: 8 nodes, 0 characters, 6 attributes > Loading net.sf.saxon.event.MessageEmitter > Building tree for file:/D:/in2.xsl using class > net.sf.saxon.tinytree.TinyBuilder > Tree built in 0 milliseconds > Tree size: 41 nodes, 0 characters, 20 attributes > Execution time: 78 milliseconds > Memory used: 945440 > NamePool contents: 17 entries in 17 chains. 6 prefixes, 6 URIs > > > <?xml version="1.0" encoding="UTF-8"?> > <root> > <row name="r1" id="0"/> > <row name="r1" id="1"/> > <row name="r1" id="2"/> > <row name="r1" id="3"/> > <row name="r1" id="4"/> > <row name="r1" id="5"/> > <row name="r1" id="6"/> > <row name="r1" id="7"/> > <row name="r1" id="8"/> > <row name="r1" id="9"/> > <row name="r1" id="10"/> > <row name="r1" id="11"/> > <row name="r1" id="12"/> > <row name="r1" id="13"/> > <row name="r1" id="14"/> > <row name="r1" id="15"/> > <row name="r2" id="0"/> > <row name="r2" id="1"/> > </root> > > As you can see above "r1" id values from 16 to 20 are mysteriously > missing in the actual output... > Is this a bug with saxon or do you see something wrong somewhere else ? Well that stylesheet looks at its own tree to process as many nodes as are in there but it looks as if there are not enough nodes in your stylesheet. As you are using Saxon 9 and it supports XSLT 2.0 you don't need that document('') stuff at all, you can simply use e.g. <xsl:template match="root/row"> <xsl:variable name="r" select="."/> <xsl:for-each select="@idMin to @idMax"> <row name="{$r/@name}" id="{.}"/> </xsl:for-each> </xsl:template> -- Martin Honnen http://msmvps.com/blogs/martin_honnen/ ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@... https://lists.sourceforge.net/lists/listinfo/saxon-help |
|
|
Re: XML data transformation problem> As you can see above "r1" id values from 16 to 20 are mysteriously > missing in the actual output... that's the xslt 1 trick of iterating over a "random" set of nodes, but you need to have enough nodes, you have <xsl:variable name="random-nodes" select="document('')//*" /> but there are only 16 elements in your stylesheet so <xsl:for-each select="$random-nodes[position() <= $nnodes]"> will never get past 16. However you are using saxon 9 so can use xslt2 which makes this so much easier <xsl:variable name="here" select="."> <xsl:for-each select="@idMin to @idMax"> <row name="$here/@name" id="."/> </xsl:for-each> is all you need. David ________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________ ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@... https://lists.sourceforge.net/lists/listinfo/saxon-help |
|
|
Re: XML data transformation problemYour solution works and looks fine, thanks a lot...
Best regards, Martin Honnen a écrit : > Damien BOUCHET wrote: > > >> I tried this transformation with the following xsl file (slightly >> modified but mainly constructed thanks to a Jeni Tennison mail : >> http://www.biglist.com/lists/xsl-list/archives/200104/msg00869.html) >> >> <?xml version="1.0" encoding="UTF-8"?> >> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >> version="1.0"> >> <xsl:output indent="yes" method="xml" media-type="text/xml; >> charset=UTF-8"/> >> <xsl:variable name="random-nodes" select="document('')//*" /> >> >> <xsl:template match="root"> >> <xsl:element name="root"> >> <xsl:apply-templates /> >> </xsl:element> >> </xsl:template> >> >> <xsl:template match="root/row"> >> <xsl:variable name="name" select="@name" /> >> <xsl:variable name="min" select="@idMin" /> >> <xsl:variable name="nnodes" select="(@idMax - @idMin) + 1" /> >> <xsl:for-each select="$random-nodes[position() <= $nnodes]"> >> <row> >> > > > >> but I only got the following output : >> >> # java -jar "d:\Software\Saxon\saxon9.jar" -t -s:in2.xml -xsl:in2.xsl >> -o:out2.xml >> Saxon 9.1.0.7J from Saxonica >> Java version 1.6.0 >> Warning: at xsl:stylesheet on line 2 column 80 of in2.xsl: >> Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor >> Stylesheet compilation time: 406 milliseconds >> Processing file:/D:/in2.xml >> Building tree for file:/D:/in2.xml using class >> net.sf.saxon.tinytree.TinyBuilder >> Tree built in 0 milliseconds >> Tree size: 8 nodes, 0 characters, 6 attributes >> Loading net.sf.saxon.event.MessageEmitter >> Building tree for file:/D:/in2.xsl using class >> net.sf.saxon.tinytree.TinyBuilder >> Tree built in 0 milliseconds >> Tree size: 41 nodes, 0 characters, 20 attributes >> Execution time: 78 milliseconds >> Memory used: 945440 >> NamePool contents: 17 entries in 17 chains. 6 prefixes, 6 URIs >> >> >> <?xml version="1.0" encoding="UTF-8"?> >> <root> >> <row name="r1" id="0"/> >> <row name="r1" id="1"/> >> <row name="r1" id="2"/> >> <row name="r1" id="3"/> >> <row name="r1" id="4"/> >> <row name="r1" id="5"/> >> <row name="r1" id="6"/> >> <row name="r1" id="7"/> >> <row name="r1" id="8"/> >> <row name="r1" id="9"/> >> <row name="r1" id="10"/> >> <row name="r1" id="11"/> >> <row name="r1" id="12"/> >> <row name="r1" id="13"/> >> <row name="r1" id="14"/> >> <row name="r1" id="15"/> >> <row name="r2" id="0"/> >> <row name="r2" id="1"/> >> </root> >> >> As you can see above "r1" id values from 16 to 20 are mysteriously >> missing in the actual output... >> Is this a bug with saxon or do you see something wrong somewhere else ? >> > > Well that stylesheet looks at its own tree to process as many nodes as > are in there but it looks as if there are not enough nodes in your > stylesheet. > > As you are using Saxon 9 and it supports XSLT 2.0 you don't need that > document('') stuff at all, you can simply use e.g. > <xsl:template match="root/row"> > <xsl:variable name="r" select="."/> > <xsl:for-each select="@idMin to @idMax"> > <row name="{$r/@name}" id="{.}"/> > </xsl:for-each> > </xsl:template> > > -- *Damien BOUCHET* *THALES SECURITY SYSTEMS* *Secured ICT Solutions - TDI - TDT* *Responsable de Lot Logiciel* *20-22 Rue Grande Dame-Rose* *78141 Vélizy Cedex - France* *Tel : +33 (0) 1 73 32 25 09* *Fax : +33 (0) 1 73 32 20 22* *Mob : +33 (0) 6 30 31 13 74* *e-mail : **damien.bouchet@...* <mailto:damien.bouchet@...> *Web : http://www.thalesgroup.com/security-services* ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@... https://lists.sourceforge.net/lists/listinfo/saxon-help |
|
|
Re: XML data transformation problem> <xsl:for-each select="$random-nodes[position() <= $nnodes]">
This coding device (sometimes called the Piezian method, I believe) relies on $random-nodes being a node-set containing at least $nnodes nodes. It's quite unnecessary in XSLT 2.0 as you can write <xsl:for-each select="1 to $nnodes">. Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@... https://lists.sourceforge.net/lists/listinfo/saxon-help |
| Free embeddable forum powered by Nabble | Forum Help |