Subject: Re: [xsl] Looking for "real-world" XML documents From: "Eliot Kimber ekimber@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 1 Nov 2014 21:12:21 -0000 |
The GitHub project dita-community/org.dita-community.common.xslt (https://github.com/dita-community/org.dita-community.common.xslt) includes the general-purpose relpath_util.xsl, which provides a pretty comprehensive set of URL and OS path manipulation functions, including functions getParent(), getName(), getNamePart(), and getRelativePath(). While this code is packaged as a DITA Open Toolkit plugin, it's just a normal XSLT2 module. relpath_util.xsl has no dependencies on any other modules. Cheers, E. bbbbb Eliot Kimber, Owner Contrext, LLC http://contrext.com On 11/1/14, 1:58 PM, "Syd Bauman s.bauman@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: >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,'_',$vSess >>ion,'_',$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] Looking for "real-world" , Dimitre Novatchev dn | Thread | [xsl] XSLT 3.0: What is the default, Dimitre Novatchev dn |
Re: [xsl] Looking for "real-world" , Dimitre Novatchev dn | Date | [xsl] XSLT 3.0: What is the default, Dimitre Novatchev dn |
Month |