Re: Using Lookup file in XSLT to cross reference old and pull in new numbers

"Martin Honnen [email protected]" <[email protected]> Tue, 6 Apr 2021 20:27:58 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Organization Liberty Development
Message-ID <[email protected]>
On 06.04.2021 19:05, Deiter, Cathy E (US) [email protected] wrote:
> I am a Newbie and am having difficulties with an XSLT doing a lookup. I
> need to lookup up an old file number based off of an attribute, look at
> the lookup file and pull in the new number. I am using Oxygen Editor
> version 22.1.
>
> My XML file looks like this. I need to find the highlighted file in my
> lookup and replace with the new file number.
> <proc>
> <title>FOLLOW-ON MAINTENANCE</title>
> <step1 id=3D"M20340-03.01.01">
> <para> Install access cover. <xref wpid=3D"M20236" pretext=3D"(" posttext=
=3D")"/>
> </para>
> </step1>
> <step1 id=3D"M20340-03.01.02">
> <para> Fill cooling system to proper fluid level. <xref wpid=3D"M20333"
> pretext=3D"(" posttext=3D")"/>
> </para>
> </step1>
>
> My Lookup file looks like this (only added a few rows)
> <row><NewFile id=3D"M20236">M20016-9-2350-372</Newfile></row>
> <row><NewFile id=3D"M20234">M20381-9-2350-372</Newfile></row>
> <row><NewFile id=3D"M20232">M20017-9-2350-372</Newfile></row>
>
> This is my XSLT:
> <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> <xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform
> <http://www.w3.org/1999/XSL/Transform>"
> xmlns:xs=3D"http://www.w3.org/2001/XMLSchema
> <http://www.w3.org/2001/XMLSchema>"
> exclude-result-prefixes=3D"xs"
> version=3D"2.0">
> <xsl:output method=3D"xml" indent=3D"yes"/>
> <xsl:include href=3D"copy.xsl"/>
>
> <xsl:template match=3D"xref">
> <xsl:variable name=3D"OLDFILE"><xsl:value-of select=3D"./@wpid"/></xsl:va=
riable>
> <xsl:variable
> name=3D"NEWFILE">file:///C:/BAE/FAASV/OldnumberFAASV/Newfile_lookup.xml</=
xsl:variable>
> <xref>
> <xsl:attribute name=3D"wpid">
> <xsl:choose>
> <xsl:when test=3D"$OLDFILE =3D document($NEWFILE)//NewFile/@id">
> <xsl:value-of select=3D"document($NEWFILE)//NewFile[@id=3D$OLDFILE]"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:copy-of select=3D"."></xsl:copy-of>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:attribute>
> </xref>
> Currently it is only returning the original value, not the new file numbe=
r.

The check in the xsl:when should work I think, unless one of the XML
files uses namespaces you haven't shown in the samples.

On the other hand, "it is only returning the original value" sounds odd
or suggests not even the
   match=3D"xref"
works (due to namespaces?), as with a match for those elements where the
xsl:when doesn't evaluate to true you would simply create a new "xref"
with an empty "wpid" attribute as your "xref" input elements are empty,
meaning the <xsl:copy-of select=3D"."></xsl:copy-of> can't create any outpu=
t.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/3329386
or by email: [email protected]
--~--