Re: [xsl] using {} brackets with xsl:result-document href (Saxon 7.4)

Subject: Re: [xsl] using {} brackets with xsl:result-document href (Saxon 7.4)
From: "malcolm macaulay" <malcolm_xslt_list@xxxxxxxxxxx>
Date: Wed, 23 Apr 2003 05:11:34 +1200
Thanks Jeni!

That is now crystal clear. I have been using {} for a while but I totally misunderstood what it was doing.

cheers

Malcolm


From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: "malcolm macaulay" <malcolm_xslt_list@xxxxxxxxxxx>
CC: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] using {} brackets with xsl:result-document href (Saxon 7.4)
Date: Tue, 22 Apr 2003 16:13:37 +0100


Hi Malcolm,

> Can someone please explain why I need to use {} bracket in the href
> of xsl:results-document?

The href attribute can take a literal value. For example:

  <xsl:result-document href="index.html">
    ...
  </xsl:result-document>

tells the processor to associate the result document with the URI
"index.html".

If you want to have the path to the result document you're creating be
dependent on something you compute within the stylesheet then use the
attribute value template:

  <xsl:result-document href="{$vFilePath}">
    ...
  </xsl:result-document>

The XPath expression within the {}s is evaluated and the string value
is inserted into the attribute value. Then the attribute value is used
as normal. So if $vFilePath had the value 'index.html', this would be
exactly the same as using 'index.html' literally as above.

> I'm familiar with using {} as a shortcut for writing values into
> output attributes but I'm not sure why I can't do something like:
>
> <xsl:result-document href="string($vFilePath) ...

This means that the URI associated with the result document is,
literally, "string($vFilePath)". That isn't a legal URI, which is why
Saxon is objecting to it.

> Below are some examples of xsk:result-document which have confused
> me.
[snip]
> This works..
>
> <xsl:template match="file">
> <xsl:variable name="vFileName" select="concat( 'file:///' , @path ,
> $fileSep , 'test.xml' )"/>
> <xsl:result-document href="{$vFileName}" >
> <x>output..</x>
> </xsl:result-document>
> </xsl:template>


Here, the value of the $vFileName is used as the value of the href
attribute. Since the value of $vFileName is a string which is a legal
URI, this is fine.

> This does not work.... Saxon says : The system identifier of the principal
> output file is unknown..
>
> <xsl:template match="file">
> <xsl:variable name="vFileName" select="concat( 'file:///' , @path ,
> $fileSep , 'test.xml' )"/>
> <xsl:result-document href="$vFileName" >
> <x>output..</x>
> </xsl:result-document>
> </xsl:template>


Here, the literal string "$vFileName" is used as the URI. That isn't a
valid URI, so Saxon objects to it.

> This works..
>
> <xsl:template match="file">
>
> <xsl:result-document href="{'file:///'}{@path}{$fileSep}{'test.xml'}" >
> <x>output..</x>
> </xsl:result-document>
> </xsl:template>


Each XPath expression is evaluated and inserted in place. The result
is a legal URI, so Saxon does not object. It would be exactly the same
if you used:

  <xsl:result-document href="file:///{@path}{$fileSep}test.xml">
    ...
  </xsl:result-document>

There's no need to use {}s for literal strings.

> This does not work.... Saxon says : The system identifier of the principal
> output file is unknown..
>
> <xsl:template match="file">
> <xsl:variable name="vFileName" select="concat( 'file:///' , @path ,
> $fileSep , 'test.xml' )"/>
> <xsl:result-document href="string($vFileName)" >
> <x>output..</x>
> </xsl:result-document>
> </xsl:template>


Again, the literal string "string($vFileName)" is not a URI, so Saxon
objects to it.

>         This works...
>         -->
>         <xsl:template match="file">
>                 <xsl:result-document href="file:///{@path}\test.xml"  >
>                         <x>output..</x>
>                 </xsl:result-document>
>         </xsl:template>

Right. A string made up of 'file:///', the value of the path
attribute, and '\test.xml' is a legal URI.

> This does not work.... Saxon says : The system identifier of the principal
> output file is unknown..
>
> <xsl:template match="file">
> <xsl:result-document href="concat( 'file:///' , @path , $fileSep ,
'test.xml' )">>
> <x>output..</x>
> </xsl:result-document>
> </xsl:template>


Again, the literal string "concat(...)" is not a legal URI so Saxon
objects to it.

Basically, if you put it in {}s it gets evaluated. If you don't, it
gets treated as a literal string.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* http://join.msn.com/?page=features/junkmail



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread