Re: [xsl] Split into numbered files: without side-effect? (XSLT 2)

Subject: Re: [xsl] Split into numbered files: without side-effect? (XSLT 2)
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 28 Sep 2007 12:57:32 +0100
  1) I'm still "cheating" somehow, by using saxon:evaluate. If I wanted to 
  do without, which way would I have to go, roughly? (Is this related to 
  Joe's comment "if the full XPaths are stored in the config file then 
  some extension is needed to evaluate these dynamically"?)

It depends what you "paths" are like. The problem of executing xpaths
supplied at runtime is a general one unrelated to the particular use

XSLt has no way of evaluating a string as an XPath (in princiiple an
xslt compiler may have parsed everything into internal form so the
runtime system need not have any Xpath parser to hand at all.
people cooming from interpretted languages (or even compiled ones0 find
this strange, but it's no different from say, C, where you can't just
pass in a string of C syntax at run time and expect a compiled c program
to know whet to do with it unless it is linked to a C compiler.

Very often though (eg sorting tables) you just need to specify an
element name, not a full path and that can be done with


if $name is the dynamically supplied string.

If you know it's always a two part path with 2 names you can of course


but this gets tedious if you want to be able to specify arbitrary paths.

So if youi want to specify arbitrary paths you need to get hold of the
Xpath parser and xpath execution of your system

saxon provides a saxon:evaluate but the way of doing it without an
extension is to present teh xpaths as part of a stylesheet that you
import, so instead of a configuration file like

<path name="a">a/b/c</path>
<path name="a">a/b/d</path>
<path name="a">a/b[not(@foo)]/z</path>

You use

<xsl:stylesheet ...>
<xsl:function name="my:path">
  <xsl:param name="node" as="node()"/>
  <xsl:param name="name" as="xs:string"/>
  <xsl:when test="$name='a'"><xsl:sequence select="$node/a/b/c"/></xsl:when>
  <xsl:when test="$name='b'"><xsl:sequence select="$node/a/b/d"/></xsl:when>

which you use as

<xsl:import href="..."/>


which will look up "path b" relative to the current node, where "path b"
is as specified in the configuration file.

If you don't want to write teh configuration as xsl:function syntax,
then you can write it in any syntax you wnat (eg <x><path... as above)
and just "precompile" it into an xsl:function using a simple XSLt

> I would prefer to avoid processing the full 

usual model is

<xsl:result-documemt href="main output">
<xsl:for-each select="something">
<xsl:variable name="chunk">
<xsl:copy-of select="$chunk"/><!-- to main output-->
<xsl:result-document href="chunk{position()}">
<xsl:copy-of select="$chunk"/><!-- to this chunk-->


The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 

Current Thread