Subject: Re: inconsistent results from stylesheet From: "Steve Muench" <smuench@xxxxxxxxxxxxx> Date: Mon, 17 Apr 2000 16:52:28 -0700 |
Bob, Using our latest production release 2.0.2.7, the following test program does what you're trying to do, but I get the correctly re-sorted data formatted by the final XSLT stylesheet into HTML with the order of the <a> cells sorted. Hope this helps find what might be awry in your environment. (P.S. If you've got a database, why not let *it* do the ORDER BY instead of doing DOM tree surgery?) thanks. import oracle.xml.parser.v2.*; import org.w3c.dom.*; import java.io.*; public class Bob { private static DOMParser dp = null; private static XMLDocument getXML(String name) throws Throwable { if (dp==null) dp = new DOMParser(); dp.parse(new FileInputStream(name)); return (XMLDocument)dp.getDocument(); } public static void main(String[] args) throws Throwable { // setup (overall question: Why not let database do the sorting?) XMLDocument xmlsrc = getXML("Bob.xml"); XMLDocument xml2htmlsrc = getXML("xml2html.xsl"); XMLDocument bobsortsrc = getXML("identitysort.xsl"); XSLStylesheet xml2html = new XSLStylesheet(xml2htmlsrc,null); XSLStylesheet bobsort = new XSLStylesheet(bobsortsrc,null); XSLProcessor p = new XSLProcessor(); // remember <rowset> element Node whereRowsetIs = xmlsrc.selectSingleNode("//rowset"); // Transform orig sort to get "sorted" <rowset> data. DocumentFragment df = xmlsrc.transformNode(bobsort); // Find the <rowset> in the sorted document Node sortedRowset = ((XMLNode)df.getFirstChild()).selectSingleNode(".//rowset"); // Insert the new sorted <rowset> and remove the old one whereRowsetIs.getParentNode().insertBefore(sortedRowset,whereRowsetIs); whereRowsetIs.getParentNode().removeChild(whereRowsetIs); // Transform original doc with surgically inserted sorted <rowset> to HTML p.processXSL(xml2html,xmlsrc,System.out); } } Produces the expected (sorted) HTML results of: <html> <body> <table> <tr> <td>11</td> <td>Bob</td> </tr> <tr> <td>12</td> <td>Steve</td> </tr> </table> </body> </html> When fed the following three files: <!-- Bob.xml --> <resultset> <rowset> <row><a>12</a><b>Steve</b></row> <row><a>11</a><b>Bob</b></row> </rowset> </resultset> <!-- IdentitySort.xsl --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match='rowset'> <xsl:copy> <xsl:apply-templates select='row'> <xsl:sort select='a' data-type='number'/> </xsl:apply-templates> </xsl:copy> </xsl:template> </xsl:stylesheet> <!-- xml2html.xsl--> <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'> <xsl:output method="html"/> <xsl:template match="/"> <html><body><table> <xsl:for-each select="//rowset/row"> <tr> <td><xsl:value-of select="a"/></td> <td><xsl:value-of select="b"/></td> </tr> </xsl:for-each> </table></body></html> </xsl:template> </xsl:stylesheet> ______________________________________________________________ Steve Muench, Lead XML Evangelist & Consulting Product Manager Business Components for Java & XSQL Servlet Development Teams Oracle Rep to the W3C XSL Working Group ----- Original Message ----- From: "Bob White" <milkchaser@xxxxxxxxx> To: "XSL XSL" <XSL-List@xxxxxxxxxxxxxxxx> Sent: Monday, April 17, 2000 2:53 PM Subject: inconsistent results from stylesheet | I am using the Oracle XSLT processor to translate XML into HTML. My | XML is pulled from an Oracle DB as a DOM document, then I apply my | parsed XSL stylesheet. Works fine the first time. | | When the user requests that the results be sorted, I apply a second | stylesheet with little more than an xsl:sort command to sort the data | section of my document (all other nodes are simply copied from the | source tree to the result tree). The sort operation leaves me with a | document-fragment. I find the node in my original XML DOM document | that matches the root of the sorted document-fragment and I replace | that node with the sorted data. | | Then I re-apply my XML-to-HTML stylesheet again to the sorted data. | But the second time I apply my stylesheet, it does not work. | | My XML looks like this: | <RESULTSET> | <COLUMNLIST>...</COLUMNLIST> | <ROWSET> | <ROW> | <C1>...</C1> | <C2>...</C2> | <C3>...</C3> | </ROW> | ... | </ROWSET> | </RESULTSET> | | What could be simpler? I have a template for the data section that | matches on the <ROWSET> tag. | | <xsl:template match="ROWSET"> | <xsl:message> | Inside ROWSET template... | </xsl:message> | <xsl:for-each select="ROW[position() = ($SkipRows+1)]"> | ... | </xsl:for-each> | </xsl:template> | | The first time I apply my stylesheet, I see this message and I know | that the template is being applied as expected. But the second time | I apply this stylesheet, this template does not fire. Instead, I see | the default template fire for the <ROWSET> node: | | <xsl:template match="*|/"> | <xsl:message> | Applying templates from default "*|/" template, | node:<xsl:value-of select="name()" />!! | </xsl:message> | ... | </xsl:template> | | This puts a console message of: | Applying templates from default "*|/" template, | node:ROWSET!! | | I have worked around this problem by naming my "ROWSET" template and | explicitly calling my ROWSET template from the "*|/" template as | follows: | <xsl:if test="name()='ROWSET'"> | <xsl:call-template name="insert-rowset"/> | </xsl:if> | | This works, but shouldn't the template fire based on the | match="ROWSET" attribute? | <xsl:template match="ROWSET" name="insert-rowset"> | ... | </xsl:template> | | Is this a bug in the Oracle processor? | | ..Bob. | | ===== | -- Bob White -- | See photos of Oxana, my beautiful bride! | http://milkchaser.tripod.com | 203-926-1888 x3287 | "Make it legal" -- www.norml.org | | __________________________________________________ | Do You Yahoo!? | Send online invitations with Yahoo! Invites. | http://invites.yahoo.com | | | 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 |
---|
<- Previous | Index | Next -> |
---|---|---|
inconsistent results from styleshee, Bob White | Thread | Re: inconsistent results from style, Bob White |
Re: faq, miles thompson | Date | position() problem with // axis + p, Warren Hedley |
Month |