[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Find the root element from an attribute node

Subject: Re: Find the root element from an attribute node
From: "Vladimir Nesterovsky" <vladimir@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 11 Jul 2008 18:39:11 +0300
Re:  Find the root element from an attribute node
You may use

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns="http://www.w3.org/1999/xhtml"
 xpath-default-namespace="http://www.w3.org/1999/xhtml"
...


OK. So none of these work - and why not? Do I really have to assign a
namespace? Remember, I'm processing documents from different namespaces so
I'd rather not.

Here is an example of the document followed by the xsl that doesn't work.

Document:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="file:/c:/SSPub/15/17/System/xhtml/css/xhtml.css"
type="text/css"?>
<!DOCTYPE html SYSTEM
"file:/c:/SSPub/15/17/System/xhtml/dtd/xhtml1-transitional.dtd">
<html id="a-4238b08e-10f858ce772--2dd4"
xmlns="http://www.w3.org/1999/xhtml">
</html>

Xsl:
<?xml version='1.0'?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/html">
Boo to a goose
</xsl:template>
</xsl:stylesheet>

Is there a way to say "any namespace"? Why isn't that the default?

Thanks,
Richard

-----Original Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
Sent: 10 July 2008 15:00
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Find the root element from an attribute node

I want to detect
whether the ancestor of the particular href is <html> as opposed to
<map>, <task>, <concept> or <reference> so that I can treat it
differently. How do I do it?

<xsl:template match="@href[ancestor::html]">


Is never going to work.

Why not? match="html//@href" is more conventional, but your form is just as
good. It assumes, of course, that you somewhere do apply-templates to the
attribute node.


I've read with bewilderment the
threads about the xslt spec and that attributes are children of
elements but elements are not parents of children...

No you've got that the wrong way around.


The relationship between elements and subelements is called "child" in one
direction and "parent" in the other.

The relationship between elements and attributes is called "attribute" in
one direction and "parent" in the other.

You can always go up from an attribute using the parent or ancestor axes.

Michael Kay
http://www.saxonica.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.