[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Looking for "real-world" XML documents


Subject: Re: [xsl] Looking for "real-world" XML documents
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 1 Nov 2014 03:44:06 -0000

On Fri, Oct 31, 2014 at 7:14 PM, Syd Bauman s.bauman@xxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> Here is an extract from a stylesheet I wrote to do some crunching on
> Senate votes for the 111th and 112th congress. (Don't know why I was
> selecting only votes 100 to 200.) Suggested improvements welcome.

 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.

I got:

Congress 111, Session 1, votes: 396, lowest 1, highest 397

Congress 111, Session 2, votes: 297, lowest 2, highest 297

Congress 112, Session 1, votes: 234, lowest 2, highest 235

Congress 112, Session 2, votes: 249, lowest 2, highest 251


Here is the transformation:


<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>


-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.


Current Thread