Subject: RE: [xsl] Temporary tree elements and namespaces: Further question From: "Marroc" <marrocdanderfluff@xxxxxxxxxxx> Date: Fri, 15 Feb 2008 13:28:30 -0000 |
Thanks Sam, thanks Florent - I appreciate the effort you guys put in to explaining this. I solved this in a similar way to you Sam only I set up a dummy namespace xmlns:map="local" and applied it both in my input file and in my transform. I then used a variable to take the value of @href from the current context which was <xhtml:a href="... so I ended up with: <xsl:variable name="mappings" select="document('map.map')"/> <xsl:template match="xhtml:a"> <xsl:variable name="href" select="@href"/> ... <xsl:value-of select="concat($helppath, ($mappings//map:relationship[@topic=$href]/@toc))"/> ... I think that my problem was that I couldn't (still can't) understanding why the current context didn't apply to the @href inside the concat expression. At what point does the current context ( <a href.. in the default xhtml namespace) cease to apply? As for why, Florent, I want links within content pages to include the target content page and the correct table of contents file. I'm working on xhtml published from another tool and don't have much control over the output structure but these two files must remain synchronised. Richard -----Original Message----- From: Sam Byland [mailto:shbyland@xxxxxxxxxxx] Sent: 14 February 2008 19:42 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Temporary tree elements and namespaces: Further question Richard, > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:xhtml="http://www.w3.org/1999/xhtml" > xmlns="http://www.w3.org/1999/xhtml" > exclude-result-prefixes="xhtml"> Since you are using XSLT 1.0, setting the default namespace (xmlns=http://www.w3.org/1999/xhtml) will affect literal result elements heading to the output document, so in this case any literal result element written to the output document will end up in the "http://www.w3.org/1999/xhtml" namespace by default. For pattern matching, expressions, etc., in the stylesheet, names with no prefix will still refer to the null namespace. So the following: > <mappings> > <relationship topic="1561.htm" toc="toc9497.htm" /> <relationship > topic="950.htm" toc="toc.htm" /> . > . > </mappings> > > Which I load into a variable as follows: > > <xsl:variable name="mappings" > select="document('map.map')/mappings/relationship" /> > > Which I'm assuming loads _all_ the relationships into $mappings. is correct -- all relationships will be selected because no prefix means no namespace, and as you indicated, map.map elements are in the null namespace. > <xsl:value-of select="$mappings/relationship[@topic=@href]/@toc"> > > Where @href is in the default xhtml namespace and @topic and @toc are > in the new namespace. > > The question is, where do I declare the new namespace and how do I > ensure it is applied to the relationships and attributes in map.map? Even with Florent's correction: <xsl:value-of select="mappings[@topic eq @href]/@toc"/> I'm not sure what you're looking to do here since @href is not an attribute of anything in $mappings. However, you seem to indicate that @href is from another file perhaps, and is an attribute of an element that is in the http://www.w3.org/1999/xhtml namespace.... You can still handle that since you also defined the xhtml prefix to be bound to that namespace. Example: Assume map.map is the following XML document: <mappings> <relationship topic="1561.htm" toc="toc9497.htm"/> <relationship topic="950.htm" toc="toc.htm"/> </mappings> and assume Test.xml is the following XML document: <SomeElement xmlns="http://www.w3.org/1999/xhtml" href="1561.htm"/> Then the following XSLT (adapted from your snippets of code and includes Florent's correction): <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xhtml"> <xsl:variable name="mappings" select="document('map.map')/mappings/relationship" /> <xsl:variable name="xhtmlMappings" select="document('Test.xml')"/> <xsl:template match="mappings"> <LiteralResultElement> <xsl:value-of select="$mappings[@topic=$xhtmlMappings/xhtml:SomeElement/@href]/@toc"/> </LiteralResultElement> </xsl:template> </xsl:stylesheet> will output the following XML: <LiteralResultElement xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">toc9497.htm</LiteralResultElement > which you will note is an element in the http://www.w3.org/1999/xhtml namespace... Does that help? Cheers, ...sam
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Temporary tree elements a, Sam Byland | Thread | RE: [xsl] Temporary tree elements a, Michael Kay |
RE: [xsl] Grouping problem, Michael Kay | Date | RE: [xsl] Temporary tree elements a, Michael Kay |
Month |