[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] should be a simple problem
Subject: [xsl] should be a simple problem From: Tom Preston <tpreston@xxxxxxxxxxxxxxxxx> Date: Wed, 12 Dec 2001 15:15:34 -0500 |
I am new to xslt. Much of the explanation of xslt (books, websites) discuss namespace from the .xsl perspective and doesn't give examples where the -IN xml document uses namespaces. My specific problem is that when I add a namespace, the examples break. Here is a simple Michael Kay example: First without namespace (works fine): opera.xml ----------- <?xml version="1.0"?> <programme> <opera> <title>The Magic Flute</title> <composer>Mozart</composer> <date>1791</date> </opera> <opera> <title>Don Giovanni</title> <composer>Mozart</composer> <date>1787</date> </opera> <opera> <title>Ernani</title> <composer>Verdi</composer> <date>1843</date> </opera> <opera> <title>Rigoletto</title> <composer>Verdi</composer> <date>1850</date> </opera> <opera> <title>Tosca</title> <composer>Puccini</composer> <date>1897</date> </opera> <composer name="Mozart"> <fullname>Wolfgang Amadeus Mozart</fullname> <born>1756</born> <died>1791</died> </composer> <composer name="Verdi"> <fullname>Guiseppe Verdi</fullname> <born>1813</born> <died>1901</died> </composer> <composer name="Puccini"> <fullname>Giacomo Puccini</fullname> <born>1858</born> <died>1924</died> </composer> </programme> ----------- opera.xsl ----------- <html xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"> <body><center> <h1>Programme</h1> <xsl:for-each select="/programme/composer"> <h2><xsl:value-of select="concat(fullname, ' (', born, '-', died, ')')"/></h2> <xsl:variable name="c" select="."/> <xsl:for-each select="/programme/opera[composer=$c/@name]"> <p><xsl:value-of select="title"/></p> </xsl:for-each> </xsl:for-each> </center></body> </html> ----------- RUN C:\xml>java org.apache.xalan.xslt.Process -IN opera.xml -XSL opera.xsl -OUT oper a.out2 -TS PRODUCES ----------- <html> <body> <center> <h1>Programme</h1> <h2>Wolfgang Amadeus Mozart (1756-1791)</h2> <p>The Magic Flute</p> <p>Don Giovanni</p> <h2>Guiseppe Verdi (1813-1901)</h2> <p>Ernani</p> <p>Rigoletto</p> <h2>Giacomo Puccini (1858-1924)</h2> <p>Tosca</p> </center> </body> </html> ----------- NOW ADD A NAMESPACE ----------- opera.xml ----------- <?xml version="1.0"?> <programme xmlns="http://www.emilygraham.com/java/other/Opera"> ........everything else is the same </programme> ----------- with SAME xsl file ----------- ----------- RUN C:\xml>java org.apache.xalan.xslt.Process -IN opera.xml -XSL opera.xsl -OUT oper a.out2 -TS PRODUCES ----------- <html> <body> <center> <h1>Programme</h1> </center> </body> </html> ----------- This is the crux of the problem....i just don't know why; the -TS on xalan Process.class gives (with Namespace): C:\xml>java org.apache.xalan.xslt.Process -IN opera.xml -XSL opera.xsl -OUT oper a.out2 -TS file:///C:/xml/opera.xsl Line #7, Column #47: for-each, select='null': [empty node list] ---------- WHILE without the namespace you get this: C:\xml>java org.apache.xalan.xslt.Process -IN opera.xml -XSL opera.xsl -OUT oper a.out2 -TS file:///C:/xml/opera.xsl Line #7, Column #47: for-each, select='null': 10040: composer 1004d: composer 1005a: composer file:///C:/xml/opera.xsl Line #8, Column #81: value-of, select='concat(fullname, ' (', born, '-', died, ')')': Wolfgang Amadeus Mozart (1756-1791) file:///C:/xml/opera.xsl Line #9, Column #43: variable, select='.': 10040: composer file:///C:/xml/opera.xsl Line #10, Column #67: for-each, select='null': 10004: opera 10010: opera file:///C:/xml/opera.xsl Line #11, Column #45: value-of, select='title': 10006: title file:///C:/xml/opera.xsl Line #11, Column #45: value-of, select='title': 10012: title file:///C:/xml/opera.xsl Line #8, Column #81: value-of, select='concat(fullname, ' (', born, '-', died, ')')': Guiseppe Verdi (1813-1901) file:///C:/xml/opera.xsl Line #9, Column #43: variable, select='.': 1004d: composer file:///C:/xml/opera.xsl Line #10, Column #67: for-each, select='null': 1001c: opera 10028: opera file:///C:/xml/opera.xsl Line #11, Column #45: value-of, select='title': 1001e: title file:///C:/xml/opera.xsl Line #11, Column #45: value-of, select='title': 1002a: title file:///C:/xml/opera.xsl Line #8, Column #81: value-of, select='concat(fullname, ' (', born, '-', died, ')')': Giacomo Puccini (1858-1924) file:///C:/xml/opera.xsl Line #9, Column #43: variable, select='.': 1005a: composer file:///C:/xml/opera.xsl Line #10, Column #67: for-each, select='null': 10034: opera file:///C:/xml/opera.xsl Line #11, Column #45: value-of, select='title': 10036: title Can someone explain what you do differently when an element comtains a namespace? Thanks Tom XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XPath: all elements with , Hunsberger, Peter | Thread | Re: [xsl] should be a simple proble, Jeni Tennison |
Re: [xsl] multiple output, Sebastian Rahtz | Date | [xsl] XML to XML Transformation, Magick, Brian |
Month |