Skip to main content

Order of processing

2 replies [Last post]
mohitanchlia
Offline
Joined: 2006-04-24
Points: 0

I have a JAXP parser that takes following xsl:

<?xml version="1.0" encoding="UTF-8"?>

We found a first name!

for following xml:
<?xml version="1.0"?>
<?xml-stylesheet href="1.xsl" type="text/xsl"?>

Paul
McCartney

Singer
Male

I was expecting that it would print first name and rest of them wouldn't get printed. I was wondering what's the order in which parser parses the rules in xslt. I thought since I have match="firstname" before match="*" I will get firstname printed and for rest nothing will get printed.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joehw
Offline
Joined: 2004-12-15
Points: 0

The problem in the stylesheet was that the 2nd template matches every element with a "*". Because of the tree structure, element "person" would be matched first by the 2nd template, so xslt never had chance to walk through the whole tree and find "firstname".

What you need to do is to replace the match-every-thing template with one that matches all text nodes because by default the XSLT would continue processing and output text on text elements.

Here's a the stylesheet that does what you wanted to do:

We found a first name!


--Joe

mohitanchlia
Offline
Joined: 2006-04-24
Points: 0

Thanks that was a simple solution I never thought of it :)