By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,131 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,131 IT Pros & Developers. It's quick & easy.

[XSLT] could not apply "apply-templates"

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.