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

Re: [xsl] Question about isolating records

Subject: Re: [xsl] Question about isolating records
From: "Mark Wilson pubs@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 5 Sep 2015 23:54:50 -0000

My last was not quite right: I am building the key in the stylesheet that processes File 1.
PS. Lost your book when my last computer went south.

On 9/5/2015 4:46 PM, Mark Wilson pubs@xxxxxxxxxxxx wrote:
Hi Ken,
I am still missing something -- I have been building the key in File 1 with this code:
<xsl:key name="pdf-key" match="Item" use="doc('FILE2')//Shelfmark"/>

That, of course, gives me all the content of every <Items> as my pdf-number when I call
<xsl:attribute name="pdf-number" select="key('pdf-key', ., doc('test-xml.xml'))"/>

If I use:
<xsl:key name="pdf-key" match="Item" use="doc('FILE2')/Shelfmark"/>
I get nothing when I do the look-up.

Am I supposed to build the key in File2, and if so, how do I then preserve it for use in File1.
Sorry to be so dense, but I have never used keys before.

On 9/5/2015 2:48 PM, G. Ken Holman g.ken.holman@xxxxxxxxx wrote:
At 2015-09-05 21:35 +0000, Mark Wilson pubs@xxxxxxxxxxxx wrote:
I clearly am missing something.
My stylesheet (using the two records at the
bottom of this email) creates an empty @pdf-number.

<xsl:key name="pdf-key" match="Shelfmark"

That is backwards ... you want to populate the table with <Item> elements and you want the associated value for the table entry to be the <Shelfmark> value:

<xsl:key name="pdf-key" match="Item" use="Shelfmark"/>

... then you look up in the table for the desired value for Shelfmark.

        <xsl:template match="@* | node()">
        <xsl:copy copy-namespaces="no">
            <xsl:apply-templates select="@* | node()"/>

    <xsl:template match="Tag">
            <xsl:when test=". eq '852'">
name="crawford-number" select="@crawford-number"/>
name="pdf-number" select="key('pdf-key', PDF, @crawford-number)"/>

And that is incorrect as well, because the value you are looking up is the second argument, the tree is in the third argument (and it seems strange that you are picking only the one '852' value, so I'm generalizing here, but you can change it to be hard-coded if you need):

 <!--untested but I think it should work just fine-->
 <xsl:template match="Tag">
   <!--preserve the element-->
     <!--preserve all attributes-->
     <xsl:copy-of select="@*"/>
     <!--add an attribute only if there is a Crawford number-->
     <xsl:for-each select="@crawford-number">
       <!--get the value by looking up in the other document-->
       <xsl:attribute name="pdf-number"

I hope this helps.

. . . . . . Ken

p.s. review pages 319-323 of my XSLT book that you have

            <Data>General-Anzeiger fC<r
Philatelie.$bInternationales Insertions- Organ.</Data>
            <Tag crawford-number="Crawford 2411.">852</Tag>
            <Data>No.1-800. 10 Apr. 1883-15
Jan. 1913$aBritish Library$b5$cDPB$jCrawford

File 2:
        <Shelfmark>Crawford 2411.</Shelfmark>
        <Title>General-Anzeiger fC<r Philatelie.</Title>

Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/video.htm |
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ |
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx |
Google+ profile: http://plus.google.com/+GKenHolman-Crane/about |
Legal business disclaimers: http://www.CraneSoftwrights.com/legal |

--- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Current Thread