|
Subject: Re: [xsl] Looking for "real-world" XML documents From: "Syd Bauman s.bauman@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 1 Nov 2014 18:57:59 -0000 |
Wow, thank you Dimitre. I like it.
Things I learned from this & questions:
* If I had once known you can call document() with a null argument,
I had forgotten. I've gotten away with using document('/'),
because I typically call stylesheets like this on themselves. But
now I see the note at the end of
http://www.w3.org/TR/xslt20/#document, and that's certainly more
robust than my method.
* I love the "tokenize-on-slash, ignore last bit, tack what I want
on end" technique. Any reason not to use "[ position() lt last() ]"
as predicate, though?
* Does it matter at all what $vDoc is set to? As long as it's
something that will be matched by the one template in
"copyDocument" mode, it's OK, right?
> The transformation below copies to the local file system (to the
> "CongressVotes" subdirectory of the directory that contains the
> stylesheet module) *all* votes from 1 to 500 of sessions 1 and 2 of
> congresses 111 and 112.
> ...
> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
> <xsl:output omit-xml-declaration="yes" indent="yes"/>
>
> <xsl:variable name="vBase"
> select="'http://www.senate.gov/legislative/LIS/roll_call_votes/vote'"/>
>
> <xsl:variable name="vDocUri" select=
> "string-join((tokenize(document-uri(document('')), '/')
> [not(position() = last())],
> 'CongressVotes'),
> '/')"/>
>
> <xsl:template match="/">
> <xsl:variable name="vDoc" select="."/>
> <xsl:for-each select="111 to 112">
> <xsl:variable name="vCongress" select="."/>
> <xsl:for-each select="1 to 2">
> <xsl:variable name="vSession" select="."/>
> <xsl:for-each select="1 to 500">
> <xsl:variable name="vVote" select="format-number(. cast as
> xs:integer, '00000') cast as xs:string"/>
> <xsl:variable name="vURI"
> select="concat($vBase,$vCongress,$vSession,'/vote_',$vCongress,'_',$vSession,'_',$vVote,'.xml')"/>
> <xsl:apply-templates select="$vDoc[doc-available($vURI)]"
> mode="copyDocument">
> <xsl:with-param name="pUri" select="$vURI"/>
> <xsl:with-param name="pFilename"
> select="concat('vote_',$vCongress,'_',$vSession,'_',$vVote,'.xml')"/>
> </xsl:apply-templates>
> </xsl:for-each>
> </xsl:for-each>
> </xsl:for-each>
> </xsl:template>
>
> <xsl:template match="/" mode="copyDocument">
> <xsl:param name="pUri"/>
> <xsl:param name="pFilename"/>
>
> <xsl:result-document href="{$vDocUri}/{$pFilename}">
> <xsl:copy-of select="doc($pUri)"/>
> </xsl:result-document>
> </xsl:template>
> </xsl:stylesheet>
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] duplicate elimination, Ihe Onwuka ihe.onwuk | Thread | Re: [xsl] Looking for "real-world" , Dimitre Novatchev dn |
| Re: [xsl] duplicate elimination, Ihe Onwuka ihe.onwuk | Date | Re: [xsl] duplicate elimination, Ihe Onwuka ihe.onwuk |
| Month |