xsl-list
[Top] [All Lists]

Re: [xsl] Getting the path to the stylesheet [RETRY]

2012-07-06 05:38:13
Why do we need the xsl:for-each on the document('').

This sets the context to be the root node of the stylesheet, so then the
unparsed-entity-uri() function acts based on that context.  From the spec:

The unparsed-entity-uri returns the URI of the unparsed entity with the
specified name in the same document as the context node

This is very clever!  Thanks for sharing it, Ken!



On Fri, Jul 6, 2012 at 1:20 AM, Ihe Onwuka 
<ihe(_dot_)onwuka(_at_)googlemail(_dot_)com> wrote:

On Fri, Jul 6, 2012 at 2:51 AM, G. Ken Holman
<gkholman(_at_)cranesoftwrights(_dot_)com> wrote:
At 2012-07-05 15:22 +0100, Ihe Onwuka wrote:

On Thu, Jul 5, 2012 at 3:06 PM, Michael Kay <mike(_at_)saxonica(_dot_)com> 
wrote:

On 05/07/2012 15:00, Ihe Onwuka wrote:

What is the standard way of getting the absolute path to a stylesheet
so that references in the result tree can be resolved relative to it.



Call the static-base-uri() function.


Sorry for not clarifyingl, does that work for XSLT 1.0, if not  what does.


The example below shows you get the base URI of the stylesheet when using
XSLT 1.0.  I've needed this when working with the OASIS specification
stylesheets.

I hope this helps.

. . . . . . . . . . Ken

~/t/ftemp $ pwd
/Users/admin/t/ftemp
~/t/ftemp $ xslt ihe.xml ihe.xsl

Stylesheet URI: file:/Users/admin/t/ftemp/ihe.xsl

~/t/ftemp $ cat ihe.xsl
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet
[
<!NOTATION xsl SYSTEM "">
<!ENTITY static-base-uri SYSTEM "" NDATA xsl>
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:variable name="static-base-uri">
    <xsl:for-each select="document('')">
      <xsl:value-of select="unparsed-entity-uri('static-base-uri')"/>
    </xsl:for-each>
  </xsl:variable>
Stylesheet URI: <xsl:value-of select="$static-base-uri"/>
  <xsl:text>&#xa;&#xa;</xsl:text>
</xsl:template>

</xsl:stylesheet>
~/t/ftemp $ cat ihe.xml
<?xml version="1.0" encoding="UTF-8"?>
<doc/>
~/t/ftemp $


Thanks Ken. 2 questions.

Does this cover the case where the stylesheet is invoked from a pi in
the source document.

Why do we need the xsl:for-each on the document('').

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>