Re: [xsl] regexs, grouping (?) and XSLT2?

Subject: Re: [xsl] regexs, grouping (?) and XSLT2?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 12 Aug 2004 10:26:29 +0100
Hi Bruce,

>> You can access the style file using the document() function and
>> then use information from it in just the same way as you would any
>> other document.
>
> I was actually thinking/hoping to be able to specify a command-line
> parameter, though am not quite sure how that'd work. Maybe a style
> file might be named mla.csl, and one would just specify the file
> minus the extension as a parameter?

Which bit are you having the problem with? You set up a stylesheet
parameter with a top-level <xsl:param> element:

<xsl:param name="style-file-name" required="yes" as="xs:string" />

and use that in the call to the document() function (or doc()
function, if you prefer):

<xsl:variable name="styles" as="document-node()"
  select="doc(concat($style-file-name, '.csl'))" />

You might need to do some playing around with resolving relative URIs
using different base URIs to get relative filenames to work as you
want, but that's basically it.
  
> Anyway,  I can see how to read the style file to get things like 
> variables.  Like, if I want to get the "title-before" variable, I can
> just do:
>
> <xsl:variable name="title-before">
>    <xsl:value-of select="cs:title/@before"/>
> </xsl:variable>
>
> Right?

Given that the current node is the relevant node in the style file,
yep.

> But what I don't understand is how I could handle the "biborder"
> template. So, say my (non-xsl) style file says order should be:
>
> title
> origin
> location
>
> How do I get the proper <xsl:apply-template select="..."/> order
> from that?

Iterate through whatever it is that tells you the relevant order, and
apply templates to the relevant child of the source node. You haven't
provided the relevant XML, but the code will probably look something
like:

<xsl:template match="source">
  <xsl:param name="style" as="element()" />
  ...
  <xsl:variable name="source" as="element()" select="." />
  <xsl:for-each select="$style/*">
    <xsl:apply-templates select="$source/*[node-name(.) =
                                           node-name(current())]">
      <xsl:with-param name="style" select="." />
    </xsl:apply-templates>
  </xsl:for-each>
  ...
</xsl:template>

BTW, you should really start new threads when you have new questions,
and it would help us identify where you're having problems if you
showed us the XSLT that you're trying (along with the XML that you're
using -- you might already have provided it in previous mails, but it
saves time if we don't have to go back through all of them to try to
find it).

Cheers,

Jeni

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

Current Thread