Re: Output from node traversal not processing correctly
Nathan Nadeau <[email protected]> Wed, 17 Feb 2010 12:16:26 -0500
| Newsgroups | gmane.text.xml.xalan.java.user |
|---|---|
| Organization | Gleim Publications |
| Message-ID | <[email protected]> |
Tim, What's happening is you're triggering the default templates that are provided by the XSLT processor that match element and text nodes when you call <xsl:apply-templates/>. There are built in rules provided by the XSLT processor that match the different node types. The default rule for element nodes is to simply call <xsl:apply-templates/> again on its children nodes. The default rule for a text node is to print out the text to the output. So when you call <xsl:apply-templates/> in your XSL, it's actually matching all the nodes, not just the <To> element, and it's firing the default template for everything but the <To> element, which fires the more specific template that matches the <To> element. This has the effect of printing out out all the text of each of the elements. And actually it looks like it might not be matching the <To> element either, because it has a namespace in the source XML document that you're not specifying in your XSL. Your namespaces need to match between your XSL and your input XML document, otherwise the processor will not match it. Nathan Nadeau Tim Hibbs wrote: > Hi - I'm requesting some basic assistance with an XSL processing > problem. I would think this is a simple issue to resolve, but I > haven't had much luck. > Any asistance would be greatly appreciated. > > *_Issue_*: Node contents not being output as expected. > > *_Execution Context_*: > - eclipse 3.5.1, running a 2.x EJB on a local Weblogic 10.3 > server, using Java JRE jdk16.0_17 > - using eclipse Java EE Developer Tools, Oracle Weblogic > Server Tools, Oracle Common Tools > - CLASSPATH overridden to force xalan.jar, xml-apis.jar, > serializer.jar, and xercesImpl.jar before weblogic.jar > - to allow instantiation of a proper TransformerFactory > (not Weblogic's version) and use of the "debugger Interface" > (http://xml.apache.org/xalan-j/usagepatterns.html#debugging) > - Xalan-j_2_7_1 > - Input is a */DOMSource/*, wrapping an org.w3c.dom.Document. > - Relevant code: aTransformer.transform(aDOMSource, *new* > StreamResult(aFileOutputStream)); "aTransformer" is instanceof > TransformerImpl > > *_Personal Context_*: > - New to XSL, Xalan. Have taken care to try all options I can > think of before soliciting for assistance here. Don't fully understand > Debugger outputs (below). > > *_Anticipated Result_*: > <?xml version="1.0" encoding="UTF-8"?> > <html> > <body> > To: John Customer > </body> > </html> > *_Actual Result_*: > <?xml version="1.0" encoding="UTF-8"?><html> > <body>Customer Company123 Main StreetAnytownCO80134USJohn > CustomerFedex02/02/1012:01:[email protected] > 12345678Salt Lake CityUT84106US</body> > </html> > > *_XML_*: > <?xml version="1.0" encoding="UTF-8" standalone="yes"?> > <tFreightRateQuotation > xmlns="http://www.fedex.com/schemas/freightRateQuotation"> > <AccountInformation> > <CompanyName>Customer Company</CompanyName> > <Address1>123 Main Street</Address1> > <City>Anytown</City> > <State>CO</State> > <Postal>80134</Postal> > <Country>US</Country> > </AccountInformation> > <CommonData> > <To>John Customer</To> > <From>Fedex</From> > <HeaderDate>02/02/10</HeaderDate> > <HeaderTime>12:01:00</HeaderTime> > <FaxNumber>3031234567</FaxNumber> > <EmailAddress>[email protected]</EmailAddress> > </CommonData> > <RateQuote> > <QuoteNumber>1 12345678</QuoteNumber> > <OriginAddress> > <OriginCity>Salt Lake City</OriginCity> > <OriginState>UT</OriginState> > <OriginPostal>84106</OriginPostal> > <OriginCountry>US</OriginCountry> > </OriginAddress> > </RateQuote> > </tFreightRateQuotation> > *_XSL_*: > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:template match="/"> > <html> > <body> > <xsl:apply-templates /> > </body> > </html> > </xsl:template> > > <xsl:template match="To"> > To: <xsl:value-of select="."/> > <xsl:apply-templates/> > </xsl:template> > </xsl:stylesheet> > > *_Logging information (from "Debugger Interface", > _**http://xml.apache.org/xalan-j/usagepatterns.html#debugging**_)_*: > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #3, Column #26: template match='/' > STARTDOCUMENT > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #4, Column #9: html > STARTDOCUMENT > STARTELEMENT: html > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #5, Column #10: body > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #6, Column #29: apply-templates > Selected source node '#document' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #6, Column #29: apply-templates, select='null': > 10001: tFreightRateQuotation > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'tFreightRateQuotation' > (default rule) apply-templates, select='null': > 10004: AccountInformation > 10011: CommonData > 1001e: RateQuote > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'AccountInformation' > (default rule) apply-templates, select='null': > 10005: CompanyName > 10007: Address1 > 10009: City > 1000b: State > 1000d: Postal > 1000f: Country > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'CompanyName' > (default rule) apply-templates, select='null': > 10006: #text > STARTELEMENT: body > CHARACTERS: Customer Company > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'Address1' > (default rule) apply-templates, select='null': > 10008: #text > CHARACTERS: 123 Main Street > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'City' > (default rule) apply-templates, select='null': > 1000a: #text > CHARACTERS: Anytown > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'State' > (default rule) apply-templates, select='null': > 1000c: #text > CHARACTERS: CO > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'Postal' > (default rule) apply-templates, select='null': > 1000e: #text > CHARACTERS: 80134 > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'Country' > (default rule) apply-templates, select='null': > 10010: #text > CHARACTERS: US > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'CommonData' > (default rule) apply-templates, select='null': > 10012: To > 10014: From > 10016: HeaderDate > 10018: HeaderTime > 1001a: FaxNumber > 1001c: EmailAddress > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'To' > (default rule) apply-templates, select='null': > 10013: #text > CHARACTERS: John Customer > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'From' > (default rule) apply-templates, select='null': > 10015: #text > CHARACTERS: Fedex > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'HeaderDate' > (default rule) apply-templates, select='null': > 10017: #text > CHARACTERS: 02/02/10 > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'HeaderTime' > (default rule) apply-templates, select='null': > 10019: #text > CHARACTERS: 12:01:00 > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'FaxNumber' > (default rule) apply-templates, select='null': > 1001b: #text > CHARACTERS: 3031234567 > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'EmailAddress' > (default rule) apply-templates, select='null': > 1001d: #text > CHARACTERS: [email protected] > <mailto:[email protected]> > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'RateQuote' > (default rule) apply-templates, select='null': > 1001f: QuoteNumber > 10021: OriginAddress > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'QuoteNumber' > (default rule) apply-templates, select='null': > 10020: #text > CHARACTERS: 1 12345678 > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'OriginAddress' > (default rule) apply-templates, select='null': > 10022: OriginCity > 10024: OriginState > 10026: OriginPostal > 10028: OriginCountry > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'OriginCity' > (default rule) apply-templates, select='null': > 10023: #text > CHARACTERS: Salt Lake City > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'OriginState' > (default rule) apply-templates, select='null': > 10025: #text > CHARACTERS: UT > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'OriginPostal' > (default rule) apply-templates, select='null': > 10027: #text > CHARACTERS: 84106 > null Line #0, Column #0: template match='*' > file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXmlToPdf-FO.xsl > Line #0, Column #0: apply-templates > Selected source node 'OriginCountry' > (default rule) apply-templates, select='null': > 10029: #text > CHARACTERS: US > ENDELEMENT: body > ENDELEMENT: html > ENDDOCUMENT > > *_Observations_*: > - Nodes seem to be traversed properly. > - Line # and Column # don't increment after initial apply-templates > > Thanks in advance for your insights! > > /*Tim Hibbs*/*/ > /*FedEx Services > 350 Spectrum Loop > Colorado Springs, CO 80921 > 719-484-2131 > > -- Nathan Nadeau [email protected] Software Development Gleim Publications, Inc. http://www.gleim.com