[XSLT] could not apply "apply-templates"

S

Stefan Siegl

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
 
M

Marrow

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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top