[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Ken,
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" use="doc('test-xml.xml')/List/Item"/>
<xsl:template match="@* | node()">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Tag">
<xsl:choose>
<xsl:when test=". eq '852'">
<Tag>
<xsl:attribute name="crawford-number" select="@crawford-number"/>
<xsl:attribute name="pdf-number" select="key('pdf-key', PDF, @crawford-number)"/>
<xsl:value-of select="."/>
</Tag>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
On 9/5/2015 8:51 AM, Mark Wilson pubs@xxxxxxxxxxxx wrote:
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 21:35:26 -0000 |
Ken,
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" use="doc('test-xml.xml')/List/Item"/>
<xsl:template match="@* | node()">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Tag">
<xsl:choose>
<xsl:when test=". eq '852'">
<Tag>
<xsl:attribute name="crawford-number" select="@crawford-number"/>
<xsl:attribute name="pdf-number" select="key('pdf-key', PDF, @crawford-number)"/>
<xsl:value-of select="."/>
</Tag>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
On 9/5/2015 8:51 AM, Mark Wilson pubs@xxxxxxxxxxxx wrote:
Hi Ken, Thanks. I'll read up on <xsl:key> and try to implement this. Appreciate your response. Regards, Mark
On 9/5/2015 8:17 AM, G. Ken Holman g.ken.holman@xxxxxxxxx wrote:Just to get you started:
- declare a key table of "Item" elements keyed by the "Shelfmark" chlid - use the identity template to copy FILE 1 - match on the "Tag" element, copy all existing attributes - use the "crawford-number" value as the lookup value in the key table of File 2 (using the third argument of the key() function)
Rather than supply the written solution, that should be enough for you to figure things out in syntax.
I hope this helps.
. . . . . Ken
At 2015-09-05 11:10 +0000, Mark Wilson pubs@xxxxxxxxxxxx wrote:I have two XML files, File 1 and File 2. They contain the XML shown below.
<Tag>852</Tag> in File 1 has a @crawford-number. If in File 2 there is an <Item> with a <Shelfmark> equal to the value of @crawford-number, I want to add an @pdf-number attribute to the <Tag>852</Tag> in File 1 containing the value of <PDF> in File 2 like so: <Tag crawford-number="Crawford 2411." @pdf-number="016678286">852</Tag>
File 1 always contains a <Tag @crawford>852</Tag> and File 2 always contains a <Shelfmark>, but there may or may not be a match.
I have not a clue as to how to get started. Happy to answer any questions.
Mark
FILE 1: <List> <Record> <Field> <Tag>245</Tag> <Data>General-Anzeiger fC<r Philatelie.$bInternationales Insertions- Organ.</Data> </Field> <Field> <Tag crawford-number="Crawford 2411.">852</Tag> <Data>No.1-800. 10 Apr. 1883-15 Jan. 1913$aBritish Library$b5$cDPB$jCrawford 2411.$nxxk</Data> </Field> </Record> </List>
File 2: <List> <Item> <PDF>016678286</PDF> <Shelfmark>Crawford 2411.</Shelfmark> <Title>General-Anzeiger fC<r Philatelie.</Title> </Item> </List>
-- 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Question about isolating , Mark Wilson pubs@xxx | Thread | Re: [xsl] Question about isolating , G. Ken Holman g.ken. |
Re: [xsl] Question about isolating , Mark Wilson pubs@xxx | Date | Re: [xsl] Question about isolating , G. Ken Holman g.ken. |
Month |