[Home] [By Thread] [By Date] [Recent Entries]
At 2008-12-12 12:20 -0800, Fred Christian wrote:
I continue to have problems getting my brain to understand how to handle namespace problems. I think I have broken one down simple enough to get help on. (Using Saxon 9) Unprefixed names in XPath by default are names in no namespace, not names in the default namespace. You've declared the XHTML to be the default namespace. 1. Is there a way that I can write some xsl, that will give me temporary output so I can figure out what I need to add to my xsl so that "4)div#" will work without looking at the xml? (I ask this, because sometimes the xml I am working with is huge and it is easy to get lost). Two mutually exclusive solutions: (1) associate the XHTML namespace with a prefix and use the prefix in your select, or (2) declare the default XPath namespace as the XHTML namespace (because you are using XSLT 2 and not XSLT 1). But I just realized that (2) is not available to you because your XML element names are in no namespace and you need to match those, so you are stuck with (1). Change that as follows: <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
...
<xsl:for-each select="h:div">
4)<xsl:value-of select="name(.)"/>#If solution (2) were available to you it would look like the following: <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://www.w3.org/1999/xhtml">
...
<xsl:for-each select="div">
4)<xsl:value-of select="name(.)"/>#.... but it would interfere with your match= of the no-namespace elements in your XML file, so this approach is not easily available to you. It is available to you if you declare xpath-default-namespace= in multiple places in your stylesheet, but that gets awkward. Note in both cases you do not need to exclude the XSLT namespace as that is implicit. I hope this helps. . . . . . . . . . Ken -- Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes: : Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|

Cart



