[XSLT] could not apply "apply-templates"

Discussion in 'XML' started by Stefan Siegl, Jul 18, 2003.

  1. Stefan Siegl

    Stefan Siegl Guest

    Hello,

    I am trying to learn XSLT to use it in another project. I start reading
    the book "Java and XSLT" and tried the examples and they are went quite
    fine (how suprising *g*).

    Then I tried to adopt these examples to my files. Unfortunately I did
    not work even though the styleSheet is very simple. Perhaps you can help
    me with it.

    Here is the XML file is try to transform:
    -----------------------------------------

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <citywalk

    xsi:schemaLocation="http://demo.heywow.com/schema/citywalk/v0004/citywalk
    http://demo.heywow.com/schema/citywalk/v0004/citywalk.xsd"
    xmlns="http://demo.heywow.com/schema/citywalk/v0004/citywalk"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    >


    <destinationEntity>
    <userId>Landsberg</userId>
    </destinationEntity>

    <insert>

    <CTarget Id="LandsbergTarget01"
    packagePath="dlr.tourGuide.tourGuideContent.">
    <elementInfo>
    <city>Landsberg</city>
    <name>Rathaus</name>
    <description xml:lang="DE">(1) some text</description>
    <mapref mapId="LandsbergMap1-0" fromLeft="20" fromTop="10" />
    </elementInfo>
    </CTarget>

    [I simplified this! there are a lot of CTarget elements here]

    </insert>
    </citywalk>

    ----------------------------------------

    And here is the sylesheet I tried to use:
    <?xml version="1.0"?>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:eek:utput method="html" />

    <xsl:template match="/">
    <html>
    <head>
    <title> Just a test </title>
    </head>
    <body>
    <h1> start of body </h1>
    <xsl:apply-templates select="citywalk/destinationEntity"/>
    <h1> end of body</h1>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="destinationEntity">
    <h2>inside destination</h2>
    </xsl:template>
    </xsl:stylesheet>

    -------------------------------------

    When transforming the xml file using this stylesheet the
    <xsl:apply-templates ...> inside the body is not executed.

    Can you see my error?

    Thanks in advance,
    Stefan Siegl
     
    Stefan Siegl, Jul 18, 2003
    #1
    1. Advertising

  2. Stefan Siegl

    Marrow Guest

    Hi Stefan,

    This is a bit of an FAQ...

    It is because your XML has a default namespace (i.e.
    xmlns="http://demo.heywow.com/schema/citywalk/v0004/citywalk") and therefore
    you must select and match against that namespace - remembering that
    namespaces are matched on the URI rather than the namespace prefix.

    So if you try something like...

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:cw="http://demo.heywow.com/schema/citywalk/v0004/citywalk">
    <xsl:eek:utput method="html" />
    <xsl:template match="/">
    <html>
    <head>
    <title> Just a test </title>
    </head>
    <body>
    <h1> start of body </h1>
    <xsl:apply-templates select="cw:citywalk/cw:destinationEntity"/>
    <h1> end of body</h1>
    </body>
    </html>
    </xsl:template>
    <xsl:template match="cw:destinationEntity">
    <h2>inside destination</h2>
    </xsl:template>
    </xsl:stylesheet>

    you should get some expected results. Notice how the namespace (prefix
    'cw') has been declared in the stylesheet and then that namespace prefix is
    used in the selects and matches.

    Hope this helps
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator



    "Stefan Siegl" <> wrote in message
    news:bf86vv$c7her$-berlin.de...
    > Hello,
    >
    > I am trying to learn XSLT to use it in another project. I start reading
    > the book "Java and XSLT" and tried the examples and they are went quite
    > fine (how suprising *g*).
    >
    > Then I tried to adopt these examples to my files. Unfortunately I did
    > not work even though the styleSheet is very simple. Perhaps you can help
    > me with it.
    >
    > Here is the XML file is try to transform:
    > -----------------------------------------
    >
    > <?xml version="1.0" encoding="ISO-8859-1"?>
    > <citywalk
    >
    > xsi:schemaLocation="http://demo.heywow.com/schema/citywalk/v0004/citywalk
    > http://demo.heywow.com/schema/citywalk/v0004/citywalk.xsd"
    > xmlns="http://demo.heywow.com/schema/citywalk/v0004/citywalk"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > >

    >
    > <destinationEntity>
    > <userId>Landsberg</userId>
    > </destinationEntity>
    >
    > <insert>
    >
    > <CTarget Id="LandsbergTarget01"
    > packagePath="dlr.tourGuide.tourGuideContent.">
    > <elementInfo>
    > <city>Landsberg</city>
    > <name>Rathaus</name>
    > <description xml:lang="DE">(1) some text</description>
    > <mapref mapId="LandsbergMap1-0" fromLeft="20" fromTop="10" />
    > </elementInfo>
    > </CTarget>
    >
    > [I simplified this! there are a lot of CTarget elements here]
    >
    > </insert>
    > </citywalk>
    >
    > ----------------------------------------
    >
    > And here is the sylesheet I tried to use:
    > <?xml version="1.0"?>
    > <xsl:stylesheet
    > version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    >
    > <xsl:eek:utput method="html" />
    >
    > <xsl:template match="/">
    > <html>
    > <head>
    > <title> Just a test </title>
    > </head>
    > <body>
    > <h1> start of body </h1>
    > <xsl:apply-templates select="citywalk/destinationEntity"/>
    > <h1> end of body</h1>
    > </body>
    > </html>
    > </xsl:template>
    >
    > <xsl:template match="destinationEntity">
    > <h2>inside destination</h2>
    > </xsl:template>
    > </xsl:stylesheet>
    >
    > -------------------------------------
    >
    > When transforming the xml file using this stylesheet the
    > <xsl:apply-templates ...> inside the body is not executed.
    >
    > Can you see my error?
    >
    > Thanks in advance,
    > Stefan Siegl
    >
    >
     
    Marrow, Jul 18, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roxanne
    Replies:
    0
    Views:
    1,254
    Roxanne
    Jul 4, 2003
  2. Cyrille \cns\ Szymanski

    xsl apply-templates select=not(...)

    Cyrille \cns\ Szymanski, Nov 7, 2003, in forum: XML
    Replies:
    4
    Views:
    613
    Cyrille \cns\ Szymanski
    Nov 11, 2003
  3. Daryl
    Replies:
    1
    Views:
    1,826
    =?ISO-8859-1?Q?R=E9mi_Peyronnet?=
    Aug 9, 2004
  4. Vijay singh
    Replies:
    1
    Views:
    450
    Martin Honnen
    Nov 4, 2004
  5. Replies:
    3
    Views:
    1,405
Loading...

Share This Page