[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Using Lookup file in XSLT to cross reference old a

Subject: Re: Using Lookup file in XSLT to cross reference old and pull in new numbers
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 6 Apr 2021 20:27:49 -0000
Re:  Using Lookup file in XSLT to cross reference old a
On 06.04.2021 19:05, Deiter, Cathy E (US) cathy.deiter@xxxxxxxxxxxxxx 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="M20340-03.01.01">
<para> Install access cover. <xref wpid="M20236" pretext="(" posttext=")"/>
</para>
</step1>
<step1 id="M20340-03.01.02">
<para> Fill cooling system to proper fluid level. <xref wpid="M20333"
pretext="(" posttext=")"/>
</para>
</step1>

My Lookup file looks like this (only added a few rows)
<row><NewFile id="M20236">M20016-9-2350-372</Newfile></row>
<row><NewFile id="M20234">M20381-9-2350-372</Newfile></row>
<row><NewFile id="M20232">M20017-9-2350-372</Newfile></row>

This is my XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform
<http://www.w3.org/1999/XSL/Transform>"
xmlns:xs="http://www.w3.org/2001/XMLSchema
<http://www.w3.org/2001/XMLSchema>"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:include href="copy.xsl"/>

<xsl:template match="xref">
<xsl:variable name="OLDFILE"><xsl:value-of
select="./@wpid"/></xsl:variable>
<xsl:variable

name="NEWFILE">file:///C:/BAE/FAASV/OldnumberFAASV/Newfile_lookup.xml</xsl:va
riable>
<xref>
<xsl:attribute name="wpid">
<xsl:choose>
<xsl:when test="$OLDFILE = document($NEWFILE)//NewFile/@id">
<xsl:value-of select="document($NEWFILE)//NewFile[@id=$OLDFILE]"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."></xsl:copy-of>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xref>
Currently it is only returning the original value, not the new file number.

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="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="."></xsl:copy-of> can't create any output.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.