468,310 Members | 1,380 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,310 developers. It's quick & easy.

[XSLT] could not apply "apply-templates"

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:output 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
Jul 20 '05 #1
1 2609
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:output 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" <St**********@gmx.de> wrote in message
news:bf************@ID-151500.news.uni-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:output 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

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

68 posts views Thread by Marco Bubke | last post: by
15 posts views Thread by Robin Eidissen | last post: by
28 posts views Thread by fred.haab | last post: by
7 posts views Thread by andrewfsears | last post: by
94 posts views Thread by Samuel R. Neff | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.