This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: should be a simple problem


In the stylesheet, the expression

<xsl:for-each select="/programme/composer">

selects elements named "programme" and "composer" (my editors seem to have
allowed me to get away with a British spelling for once!) that are in no
namespace (or the null namespace - different ways of saying the same thing).
When you add the default namespace declaration
xmlns="http://www.emilygraham.com/java/other/Opera"; to your source document,
the "programme" and "composer" elements are now in this namespace, so the
above expression will no longer select them. To select these elements, the
stylesheet must be changed to:

<xsl:stylesheet ...
  xmlns:opera="http://www.emilygraham.com/java/other/Opera";>
...
<xsl:for-each select="/opera:programme/opera:composer">

Mike Kay

> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Tom Preston
> Sent: 12 December 2001 20:16
> To: xsl-list@lists.mulberrytech.com
> Subject: [xsl] should be a simple problem
>
>
> 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
>


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]