472,777 Members | 2,643 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,777 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 2758
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.