473,396 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

[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 2789
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

68
by: Marco Bubke | last post by:
Hi I have read some mail on the dev mailing list about PEP 318 and find the new Syntax really ugly. def foo(x, y): pass I call this foo(1, 2), this isn't really intuitive to me! Also I...
1
by: Su Wei | last post by:
i have a project want to develop with python. who can tell me that how to apply "mvc" pattern to gui-design in python. please give me some advices! ths in advanced. -- ÝëÈ»»ØÊ×Ôø¾­ËêÔ£¬...
4
by: Jian H. Li | last post by:
Hello, What's the essential differences between the two ways of "class::member" & "object.member"(or object_pointer->member)? class C{ public: void f() {} int i; };
15
by: Robin Eidissen | last post by:
What I try to do is to iterate over two variables using template metaprogramming. I've specialized it such that when it reaches the end of a row ot starts on the next and when it reaches the last...
28
by: fred.haab | last post by:
Not having server side scripting, I've been doing this for "last modified" tags on my pages: <div class="modified"> <script type="Text/JavaScript"> <!-- document.write("This page was last...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
3
by: janzon | last post by:
Hi! Sorry for the bad subject line... Here's what I mean. Suppose we deal with C++ standard integers lists (the type is indifferent). We have a function f, declared as list<intf(int); Now...
7
by: andrewfsears | last post by:
I have a question: I was wondering if it is possible to simulate the multiple constructors, like in Java (yes, I know that the languages are completely different)? Let's say that I have a class...
94
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock...
1
by: mattscho | last post by:
Re: Filter By From, Apply Filter, Remove Filter Buttons in a Form. -------------------------------------------------------------------------------- Hi All, Trying to create a set of 3 buttons in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.