[xsl] Correcting a prior error

Subject: [xsl] Correcting a prior error
From: Dave Pawson <davep@xxxxxxxxxxxxx>
Date: Fri, 30 Jul 2010 09:44:32 +0100
I've been working with a series of xhtml like files, cleaning them up.
It was a case of run an identity tranform, apply corrections.
That was the theory. 
Luckily I kept a backup.
I hastily created an incorrect version of the identity transform
which omitted to copy the contents of any attributes. 

I'm left with the problem of how to correct it.
Given 
directory A contains the files to be corrected.
directory B contains the backup set of files.

I want to match on 
"x:a[not(string(@href))]" I.e. those a elements with an empty href
attribute. 

then copy across the value of the 'matching' href in the B directory,
same file. I'm iterating through the files in A using 

 <xsl:for-each select="for $f in collection('/A?select=*.xml')
                         return $f">
 <xsl:result-document 
       href="{replace(base-uri(),'A','AA')}">
       <xsl:apply-templates/>
   </xsl:result-document>
which creates the temporary directory AA with the corrections applied. 


the problem I'm finding is picking up the correct a element in 
the second file?

Having found an empty a element

I'm trying
 <xsl:variable name="backup" select="'file:///B'"/>

  <xsl:template match="x:a[not(@href)]">
    <xsl:variable name="thisdoc" select="document-uri(/)"/>
    <xsl:variable name="base"
select="substring-after($thisdoc,'blg/')"/>
    <xsl:variable name="src" select="concat($backup,'/',$base)"
as="xs:string"/>  <!- this is the basename of the filename being worked
->

<-this is an attempt to select the 'right' a element->
    <xsl:variable name="posn" select="count(ancestor::*|preceding::*)"/>
    <xsl:variable name="val" 
      select="(document($src)//*)[$posn]/@href"/>
   

    <!-- Now copy this across -->
    <x:a href="{$val}">
      <xsl:value-of select="."/>
    </x:a>
  </xsl:template>


Can anyone spot any obvious sillies please?


regards
------------------------
Dave Pawson
http://www.dpawson.co.uk
XSLT, XSL-FO and docbook FAQ



-- 

regards 

-- 
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk

Current Thread