473,725 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT - simple match not matching as expected

I would expected that the stylesheet below would tag the
contents of the element "Date" with <b> and </b>, but it doesn't,
at least not with xsltproc. It just passes the content through
unchanged.

I've also tried diffent permutations of upper and lower case.
What have I missed?

-Lars

Stylesheet:

<xsl:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output omit-xml-declaration="ye s"
method="xml" media-type="text/xml" encoding="utf-8" />

<xsl:template match="Date">
<b> <xsl:apply-templates/> </b>
</xsl:template>

</xsl:stylesheet>

Data:
<?xml version="1.0" encoding="UTF-8" ?>
<FMPDSORESULT xmlns="http://www.filemaker.c om/fmpdsoresult">
<ROW MODID="3" RECORDID="38">
<Article_Titles .Title>
<DATA>Texan city</DATA>
</Article_Titles. Title>
<Date>2003-12-22</Date>
<Article_Quotes .Quote>
<DATA>The city is about three months</DATA>
</Article_Quotes. Quote>
</ROW>
</FMPDSORESULT>

--
Lars
"Chances are that patents on software ... in fact stifle
innovation. Europe could still alter course"
http://www.nosoftwarepatents.com/en/m/intro/
Jul 20 '05 #1
3 2317
In article <PM************ ***@news.itd.um ich.edu>,
<la**@nospam.no softwarepatents .edu> wrote:
I would expected that the stylesheet below would tag the
contents of the element "Date" with <b> and </b>, but it doesn't,
at least not with xsltproc. It just passes the content through
unchanged. <FMPDSORESULT xmlns="http://www.filemaker.c om/fmpdsoresult">
[...]
<Date>2003-12-22</Date>
The Date element is in the http://www.filemaker.com/fmpdsoresult
namespace.
<xsl:template match="Date">
<b> <xsl:apply-templates/> </b>
</xsl:template>


This matches Data elements in no namespace. You need to bind a prefix
for the namespace in the stylesheet, and use it on the template, e.g.

<xsl:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:z="http://www.filemaker.c om/fmpdsoresult"
exclude-result-prefixes="z">

....

<xsl:template match="z:Date">

-- Richard
Jul 20 '05 #2
Tempore 17:56:15, die Monday 24 January 2005 AD, hinc in foro {comp.text.xml} scripsit <la**@nospam.no softwarepatents .edu>:
I would expected that the stylesheet below would tag the
contents of the element "Date" with <b> and </b>, but it doesn't,
at least not with xsltproc. It just passes the content through
unchanged.

I've also tried diffent permutations of upper and lower case.
What have I missed?

It's a namespacing issue. Either declare and use the namespace in the xsl:
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:sfn="http ://www.filemaker.c om/fmpdsoresult" exclude-result-prefixes="sfn">

<xsl:output omit-xml-declaration="ye s"
method="xml" media-type="text/xml" encoding="utf-8" />

<xsl:template match="sfn:Date ">
<b> <xsl:apply-templates/> </b>
</xsl:template>

</xsl:stylesheet>

or leave it undefined.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output omit-xml-declaration="ye s"
method="xml" media-type="text/xml" encoding="utf-8" />

<xsl:template match="*[local-name()='Date']">
<b> <xsl:apply-templates/> </b>
</xsl:template>

</xsl:stylesheet>

The first one is most of the time better.
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Laudeo W3C et dona ferens
Jul 20 '05 #3
Thanks, Richard and Joris. The namespace issue is something new
and I will experiment with your suggestions.

---
Lars
"Chances are that patents on software ... in fact stifle
innovation. Europe could still alter course"
http://www.nosoftwarepatents.com/en/m/intro/
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2813
by: Stefan Siegl | last post by:
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.
7
1767
by: Kofi Sarfo | last post by:
Wondering what I'd use to evaluate the following to return 'Easy' <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="Answers.xsl"?> <answers> <answer> <code>A</code> <method>Easy</method> </answer> <answer>
4
2169
by: Moogy | last post by:
I'm pulling my hair out here. First, I'm new to XML, so that doesn't help, but none of this makes any sense to me. All I'm trying to do is take a simple source XML file and translate it with an XSLT to produce HTML code. The problem I have is that no matter what translation it runs through, it ALWAYS includes data that I don't match in the XSLT!! All I want to do is extract specific fields from the XML. Here's the XML source....
2
6798
by: pintihar | last post by:
I am trying to map external xml documents to a class in dotnet. The problem is that the elements of the input xml will have different names than the properties of the class. How do I create the xslt that will allow me to transform the inbound xml into another xml resource with the elements renamed so that I can serialize it to an instance of the class. I assume that this is best done with xslt.transform, but I am not sure how to write...
3
2134
by: Andy | last post by:
Hi all, I'm having a problem doing an Xslt transform in code. I've done it before, so I'm not really sure why its not working. The problem is that the result of the transform is an empty string. I expected the xml to be transformed into a plain text document. Everything works fine when i transform using XmlPad. Here's the code (which does generate the Xml properly): Sample XML:
6
1831
by: Neal | last post by:
Hi All, I used an article on XSLT and XML and creating a TOC written on the MSDN CodeCorner. ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dncodecorn/html/corner042699.htm However, it did'nt quite answer all my questions. How would one create a 3 level TOC when each item level / node was differently named (They used Template match and for-each, but the template match worked as on a 3 level structure they usedf the same named xml...
4
1519
by: Adrian von Bidder | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Yo! Mostly as a finger-exercise (and because I'm annoyed again and again how bad the existing solutions are), I'm hacking up a web-based forum (yes, the 64832th one, I know). I want to allow some simplified HTML as input language, and use some xsl
3
2790
by: abhishek.smu | last post by:
Given an XML like: <root> <node>8</node> <node>21</node> <node>-7</node> <node>13</node> <node>43</node> <node>2</node> </root>
2
7357
by: Efi Merdler | last post by:
Hello, As I understand it is impossible in xslt to change the value of a variable after you assigned a value to it. I would like to simulate a flag. For example if something happens in template A then update my flag. Template B reads the flag and according to its value decides to do something. The main idea is that template B is independent of template A, i.e.
0
8886
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8751
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9171
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9108
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6010
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4514
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3218
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.