472,371 Members | 1,479 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,371 software developers and data experts.

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:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output omit-xml-declaration="yes"
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.com/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 2256
In article <PM***************@news.itd.umich.edu>,
<la**@nospam.nosoftwarepatents.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.com/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:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:z="http://www.filemaker.com/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.nosoftwarepatents.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:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:sfn="http://www.filemaker.com/fmpdsoresult" exclude-result-prefixes="sfn">

<xsl:output omit-xml-declaration="yes"
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:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output omit-xml-declaration="yes"
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
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...
7
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>...
4
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...
2
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...
3
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...
6
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...
4
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...
3
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
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

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.