[Home] [By Thread] [By Date] [Recent Entries]
Hi,
At 09:19 AM 12/2/2009, Ken wrote: At 2009-12-01 21:46 -0500, ohaya@xxxxxxx wrote:the problem was that the match I was using was not matching anything, so that xsl:template was not "catching", and the reason for not matching was because of the namespace. In other words, if the element in the input document is in a namespace, it must be matched with a name in the same namespace, and in XSLT there are only two ways to do this. First, the namespace may be made explicit in the match pattern (even if it is only implicit elsewhere), or second, in XSLT 2.0 a top-level declaration may be used to bind unprefixed names in XPath expressions, throughout the stylesheet, to a namespace (a considerable convenience). Note that only the first option is available in XSLT 1.0. Binding unprefixed names to a namespace in the stylesheet in the usual way (with a namespace declaration) does not do this, since while it affects unprefixed names of XML elements in the stylesheet (as it is supposed to), it does not affect unprefixed names inside XPath expressions, which are only inside attribute values in the XSLT-as-XML -- that is, as "namespaces in content". An illustration: <illustration xmlns="data:,illustration"> <element attribute="value"/> </illustration> While the 'illustration' and 'element' elements are in the declared (unprefixed) namespace, there's nothing in XML that says the value "value" should be modified in any way. This is exactly analogous to: <xsl:template xmlns="data:,illustration" match="element"> ... </xsl:template> (Nor would it be wise for XSLT to specify this for its XPath expressions, if you want to think about the case where a stylesheet needs to work with elements in different namespaces, either matching them or generating them, while any or all of them may appear unprefixed in the data.) This is a very common gotcha for beginners or sometime users, since it becomes relevant as soon as namespaces come into play, and it's somewhat counterintuitive until you wrap your head around all of it -- both how namespaces work, and how XSLT stylesheets are XML documents and follow the rules thereof. Only then does it make sense: the stylesheet works only if the names are the same, but to be the same, they have to look different. Cheers, Wendell ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
|

Cart



