XSLT Matching 2 Elements to get another - xslt

I'm relatively new to XSLT but want to perform what I thought was a relatively simple match between elements to get another.
Here is a snippet from the XML. Version = 1.0 and output is text (converting xml to text).
<Accounts>
<Account>
<Id>273228MD301</Id>
<EPIProductCode>IPP4D3</EPIProductCode>
<Name>Mr John Smith</Name>
<Status>Open</Status>
<Owners>
<Owner>
<Id>273228M</Id>
</Owner>
</Owners>
<Advisers>
<Adviser>
<Id>286666</Id>
<PrimaryAdviser>true</PrimaryAdviser>
</Adviser>
</Advisers>
<Delete>false</Delete>
<LastModified>2012-06-08T15:19:19</LastModified>
</Account>
<Account>
<Id>273228MD399</Id>
<EPIProductCode>IPAAA</EPIProductCode>
<Name>Sir Leslie Patterson</Name>
<Status>Open</Status>
<Owners>
<Owner>
<Id>2732299</Id>
</Owner>
</Owners>
<Advisers>
<Adviser>
<Id>286666</Id>
<PrimaryAdviser>true</PrimaryAdviser>
</Adviser>
</Advisers>
<Delete>false</Delete>
<LastModified>2012-06-08T15:19:19</LastModified>
</Account>
<Account>
<Id>273228MD999</Id>
<EPIProductCode>IPYYY</EPIProductCode>
<Name>Dame Edna</Name>
<Status>Open</Status>
<Owners>
<Owner>
<Id>27322YY</Id>
</Owner>
</Owners>
<Advisers>
<Adviser>
<Id>286666</Id>
<PrimaryAdviser>true</PrimaryAdviser>
</Adviser>
</Advisers>
<Delete>false</Delete>
<LastModified>2012-06-08T15:19:19</LastModified>
</Account>
</Accounts>
<InvestmentHoldingBalances>
<HoldingBalance>
<AccountId>273228MD399</AccountId>
<InvestmentCode>TEST123</InvestmentCode>
<Exchange>FND</Exchange>
<UnitBalance>
<Settled Currency="AUD">0</Settled>
<Pending Currency="AUD">0</Pending>
<AsAtDate>2012-06-08T15:19:34</AsAtDate>
</UnitBalance>
<LastModified>2012-05-16T00:00:00</LastModified>
</HoldingBalance>
<HoldingBalance>
<AccountId>273228MD301</AccountId>
<InvestmentCode>0114AU</InvestmentCode>
<Exchange>FND</Exchange>
<UnitBalance>
<Settled Currency="AUD">0</Settled>
<Pending Currency="AUD">0</Pending>
<AsAtDate>2012-06-08T15:19:34</AsAtDate>
</UnitBalance>
<LastModified>2012-05-16T00:00:00</LastModified>
</HoldingBalance>
<HoldingBalance>
<AccountId>273228MD301</AccountId>
<InvestmentCode>0016AU</InvestmentCode>
<Exchange>FND</Exchange>
<UnitBalance>
<Settled Currency="AUD">0</Settled>
<Pending Currency="AUD">0</Pending>
<AsAtDate>2012-06-08T15:19:34</AsAtDate>
</UnitBalance>
<LastModified>2012-05-16T00:00:00</LastModified>
</HoldingBalance>
<HoldingBalance>
<AccountId>273228MD301</AccountId>
<InvestmentCode>0277AU</InvestmentCode>
<Exchange>FND</Exchange>
<UnitBalance>
<Settled Currency="AUD">0</Settled>
<Pending Currency="AUD">0</Pending>
<AsAtDate>2012-06-08T15:19:34</AsAtDate>
</UnitBalance>
<LastModified>2012-05-15T00:00:00</LastModified>
</HoldingBalance>
<HoldingBalance>
<AccountId>273228MD999</AccountId>
<InvestmentCode>TD0155</InvestmentCode>
<Exchange>FND</Exchange>
<UnitBalance>
<Settled Currency="AUD">0</Settled>
<Pending Currency="AUD">0</Pending>
<AsAtDate>2012-06-08T15:19:34</AsAtDate>
</UnitBalance>
<LastModified>2012-05-21T00:00:00</LastModified>
</HoldingBalance>
</InvestmentHoldingBalances>
What I'm tying to do is match nodes //Accounts/Account/Id with //InvestmentHoldingBalances/HoldingBalance/AccountId and when there is a match get the corresponding //Owners/Owner/Id that belongs to that Account Id.
The results Im getting when I do a match is the first //Owners/Owner/Id for all rows not the individual matching one. This is my xslt;
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<!-- Create Header Record -->
<xsl:template match="xxxxxx">
<!-- Some other xslt here to extract header info -->
<xsl:apply-templates select="InvestmentHoldingBalances/HoldingBalance" />
</xsl:template>
<!-- Create HoldingBalance Records -->
<xsl:template match="HoldingBalance">
<xsl:value-of select="AccountId" />
<xsl:text>","</xsl:text>
<xsl:value-of select="InvestmentCode" />
<xsl:text>","</xsl:text>
<xsl:value-of select="Exchange" />
<xsl:text>","</xsl:text>
<xsl:if test="../../Accounts/Account/Id=AccountId">
<xsl:value-of select="../../Accounts/Account/Owners/Owner/Id" />
</xsl:if>
<xsl:text>"</xsl:text>
<xsl:text disable-output-escaping="yes">
</xsl:text>
</xsl:template>
</xsl:stylesheet>
The output is the same Owner Id for each row (ie '273228M' the last column), not the matching Owner Id according to the Account Id match;
273228MD399","TEST123","FND","273228M"
273228MD301","0114AU","FND","273228M"
273228MD301","0016AU","FND","273228M"
273228MD301","0277AU","FND","273228M"
273228MD999","TD0155","FND","273228M"
The result I'm after would look like this;
273228MD399","TEST123","FND","2732299"
273228MD301","0114AU","FND","273228M"
273228MD301","0016AU","FND","273228M"
273228MD301","0277AU","FND","273228M"
273228MD999","TD0155","FND","27322YY"
Thanks for any suggestions.

The basic problem is in the
<xsl:value-of select="../../Accounts/Account/Owners/Owner/Id"/>
The select expression selects all owner ids in the whole document regardless of the account id, and when you ask for the value-of a set of more than one node the result is defined by the spec to be the value of the first node in the set in document order.
You need to somehow constrain the set to just the matching accounts, the easiest way to do this is
<xsl:value-of select="../../Accounts/Account[Id = current()/AccountId]/Owners/Owner/Id"/>
but it is likely to be more efficient to define a key at the top level of the stylesheet (put it directly after the xsl:output element)
<xsl:key name="accountById" match="Account" use="Id"/>
Then you can extract the right account in the value-of using
<xsl:value-of select="key('accountById', AccountId)/Owners/Owner/Id"/>
Either way, you don't actually need the if around the value-of, because in the case where no accounts match the current AccountId you'll be asking for the value-of an empty node set, which is the empty string by definition.
And finally, you should never need disable-output-escaping when you are using <xsl:output method="text"/> - simply <xsl:text>
</xsl:text> will work just as well here.

Related

XSLT Appending incremented value to existing attribute value

For my input XML, I have written the XSLT , But I cannot make the XSLT to generate the <mynewtag> correctly. Please help.
XML input:
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book.child.1>
<title>charithram</title>
<author>sarika</author>
</book.child.1>
<book.child.2>
<title>doublebell</title>
<author>psudarsanan</author>
</book.child.2>
</books>
Expected Output:
<?xml version="1.0" encoding="UTF-8"?>
<newbooks>
<newbook>
<mynewtag id="book1" />
<title>charithram</title>
<author>sarika</author>
</newbook>
<newbook>
<mynewtag id="book2" />
<title>doublebell</title>
<author>psudarsanan</author>
</newbook>
</newbooks>
XSLT that I tried: [I understand the syntax is incorrect for <mynewtag> ]. But I don't know to fix it to get the desired output.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes" />
<xsl:template match="/">
<newbooks>
<xsl:for-each select="books/child::*">
<newbook>
<mynewtag id="book<xsl:number value='position()' format='1' />" />
<title>
<xsl:value-of select="title" />
</title>
<author>
<xsl:value-of select="author" />
</author>
</newbook>
</xsl:for-each>
</newbooks>
</xsl:template>
</xsl:stylesheet>
Trying in Online XSLT transformer , http://www.freeformatter.com/xsl-transformer.html
I tried assigning the position to a variable, but still I face the same problem of not knowing how to append it with the attribute value book .
<xsl:variable name="cnt">
<xsl:number value='position()' format='1' />
</xsl:variable>
<xsl:value-of select = "$cnt" />
Note: If I remove the <xsl:number value='position()' format='1' /> from XSL, then the syntax is correct, but then I won't be able to generate book1 book2 etc as <mynewtag> attribute values.
Please help.
Added: <mynewtag> is a required element. It is like any other XML element like <title> that is required in output. It is not an element just to hold the attribute id. Sorry if there is a confusion on this.
Adding Solution here, from the answers obtained to summarize:
<mynewtag>
<xsl:attribute name="id">
<xsl:text>book</xsl:text>
<xsl:number value='position()'/>
</xsl:attribute>
</mynewtag>
or shortly:
<mynewtag id="book{position()}" />"
or
<newbook>
<xsl:variable name="cnt">
<xsl:number value='position()' format='1' />
</xsl:variable>
<mynewtag id="book{$cnt}" />
..........
Also the attribute value templates that IanRoberts mentioned.
You can't place a tag inside another tag. Try either:
<mynewtag>
<xsl:attribute name="id">
<xsl:text>book</xsl:text>
<xsl:number value='position()'/>
</xsl:attribute>
</mynewtag>
or shortly:
<mynewtag id="book{position()}" />"
ADDED:
Not directly related to your question, but I believe the id attribute should be applied to the parent <newbook> element, instead of creating an artificial child element to hold it.

Multiply nodes value using XSLT

I need to get a value which is coming from two different nodes in the same XML file. For instance, my xml:
<asset>
<curr_wanted>EUR</curr_wanted>
<curr>USD</curr>
<value>50</value>
</asset>
<exchangeRates>
<USD>
<USD>1</USD>
<EUR>0.73</EUR>
</USD>
</exchangeRates>
and I want to get equivalent of 50 Dollars in Euro.
I tried :
<xsl:value-of select="(Asset/value * /exchangeRates[node() = curr]/curr_wanted)"/>
But it didn't work. Also I have to use XSLT 1.0. How can I get that value in Euro?
I did not test it very much but for input like
<?xml version="1.0" encoding="UTF-8"?>
<root>
<asset>
<curr_wanted>EUR</curr_wanted>
<curr>USD</curr>
<value>50</value>
</asset>
<asset>
<curr_wanted>EUR</curr_wanted>
<curr>USD</curr>
<value>25</value>
</asset>
<exchangeRates>
<USD>
<USD>1</USD>
<EUR>0.73</EUR>
</USD>
</exchangeRates>
</root>
something like following could work
for $asset in /root/asset, $rate in /root/exchangeRates
return $asset/value*$rate/*[name() = $asset/curr]/*[name() = $asset/curr_wanted]
But it will work only in xpath 2.0 and it also depends on the whole input xml (like if there might exist more asset elements, more exchangeRates elements, etc.).
Edit: In xslt 1.0 you could use xsl:variable to store some information and prevent them from context changes during xpath evaluation. Look for example at following template
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="text" />
<!-- Store "exchangeRates" in a global variable-->
<xsl:variable name="rates" select="/root/exchangeRates" />
<xsl:template match="/root">
<xsl:apply-templates select="asset" />
</xsl:template>
<xsl:template match="asset">
<!-- Store necessary values into local variables -->
<xsl:variable name="currentValue" select="value" />
<xsl:variable name="currentCurrency" select="curr" />
<xsl:variable name="wantedCurrency" select="curr_wanted" />
<xsl:variable name="rate" select="$rates/*[name() = $currentCurrency]/*[name() = $wantedCurrency]" />
<!-- Some text to visualize results -->
<xsl:value-of select="$currentValue" />
<xsl:text> </xsl:text>
<xsl:value-of select="$currentCurrency" />
<xsl:text> = </xsl:text>
<!-- using variable to prevent context changes during xpath evaluation -->
<xsl:value-of select="$currentValue * $rate" />
<!-- Some text to visualize results -->
<xsl:text> </xsl:text>
<xsl:value-of select="$wantedCurrency" />
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
which produces following output for input xml above.
50 USD = 36.5 EUR
25 USD = 18.25 EUR

XSLT 2.0 to 1.0

Lots of help here to convert XSLT 1.0 to 2.0, but I need to go the other way!
OK, I have an XSL file working in XSLT 2.0: I need to convert this file to XSLT 1.0. Right now, I know the transformation is getting hung up on "result-document" but I'm not sure how to fix this. And, I'm not sure if my other info will translate to 1.0: will my value-of select= statements still work? help! (thanks)!
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:result-document href="output.xml" method="xml">
<playlist>
<xsl:for-each select="//dict[preceding-sibling::*[1]='Tracks']/dict">
<Track>
<Artist>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Artist']"/>
</Artist>
<Album>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Album']"/>
</Album>
<Songname>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Name']"/>
</Songname>
<TrackID>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Track ID']"/>
</TrackID>
<TagID>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Tag ID']"/>
</TagID>
</Track>
</xsl:for-each>
<xsl:for-each select="//dict[preceding-sibling::*[1]='Upload Information']">
<Description>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Playlist Description']"/>
</Description>
<Title>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Playlist Title']"/>
</Title>
<Username>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Username']"/>
</Username>
<Token>
<xsl:value-of select="child::*[preceding-sibling::*[1] = 'Token']"/>
</Token>
</xsl:for-each>
</playlist>
</xsl:result-document>
</xsl:template>
Well considering that result-document is new in XSLT 2.0 and that XSLT 1.0 without processor specific extension does not allow creating of multiple result documents at all it is in general not possible to translate stylesheets making use of result-document to XSLT 1.0.
However in your snippet the result-document instruction is inside the template matching the single / document node so you could simply remove it and use
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<playlist>
<xsl:for-each select="//dict[preceding-sibling::*[1]='Tracks']/dict">
<Track>
<Artist>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Artist']"/>
</Artist>
<Album>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Album']"/>
</Album>
<Songname>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Name']"/>
</Songname>
<TrackID>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Track ID']"/>
</TrackID>
<TagID>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Tag ID']"/>
</TagID>
</Track>
</xsl:for-each>
<xsl:for-each select="//dict[preceding-sibling::*[1]='Upload Information']">
<Description>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Playlist Description']"/>
</Description>
<Title>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Playlist Title']"/>
</Title>
<Username>
<xsl:value-of select="*[preceding-sibling::*[1][local-name()='key'] = 'Username']"/>
</Username>
<Token>
<xsl:value-of select="child::*[preceding-sibling::*[1] = 'Token']"/>
</Token>
</xsl:for-each>
</playlist>
</xsl:template>
Of course you would then need to ensure you run your XSLT processor with the right arguments to write its result to output.xml.
As for value-of, check whether any of the used expressions selects multiple nodes in your input XML documents. But you only need to check if the stylesheet had once version="2.0" and was run that way with an XSLT 2.0 processor. Your posted snippet has version="1.0", that way even an XSLT 2.0 processor would run it in backwards compatible mode where value-of semantics (output string value of first selected node) is used.
So the value-of only need adaption if with version="2.0" they output multiple values and you want to preserve that with version="1.0". You need to use for-each then e.g. by replacing
<xsl:value-of select="child::*[preceding-sibling::*[1] = 'Token']"/>
with
<xsl:for-each select="child::*[preceding-sibling::*[1] = 'Token']">
<xsl:if test="position() > 1"><xsl:text> </xsl:text></xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
The only problem with your code with xslt-1.0 would be the <xsl:result-document href="output.xml" method="xml">. This is not supported for xslt-1.0
One possible solution could be to remove this (xsl:result-document) and redirect the "stdout" output to a file. This depends on the tools you are using.
Also some xlst processor support some extensions. For example wiht xsltproc you can replace
xsl:result-document with xsl:document.

XSLT - how to apply a template to every node of the type?

I am quite new to xsl and functional programming, so I'll be grateful for help on this one:
I have a template that transforms some xml and provides an output. The problem is that there are many elements of type xs:date, all in different contexts, that must be localized. I use a concatenation of substrings of these xs:dates to produce a localized date pattern strings.
As you can guess this causes a lot of copy-paste "substring-this and substring-that". How can I write a template that will automatically transform all the elements of type xs:date to localized strings preserving all the context-aware transformations?
My xsl is something like this:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="/">
...
<input value="{substring(/select/a/date 9,2)}.{substring(/select/a/date, 6,2)}.{substring(/select/a/date 1,4)}">
...
<!-- assume that following examples are also with substrings -->
<div><xsl:value-of select="different-path/to_date"/></div>
...
<table>
<tr><td><xsl:value-of select="path/to/another/date"/></td></tr>
</table>
<apply-templates/>
</xsl:template>
<xsl:template match="something else">
<!-- more dates here -->
</xsl:template>
</xsl:stylesheet>
I hope I managed to make my question clear =)
UPD: Here is an example of xml:
<REQUEST>
<header>
<... />
<ref>
<ref_date type="xs:date">1970-01-01</ref_date>
</ref>
</header>
<general>
<.../>
<info>
<.../>
<date type="xs:date">1970-01-01</date>
<ExpireDate type="xs:date">1970-01-01</ExpireDate>
<RealDate type="xs:date">1970-01-01</RealDate>
<templateDetails>template details</templateDetails>
<effectiveDate type="xs:date">1970-01-01</effectiveDate>
</info>
<party>
<.../>
<date type="xs:date">1970-01-01</date>
</party>
<!-- many other parts of such kind -->
</general>
</REQUEST>
As for the output, there are many different options. The main thing is that these values must be set as a value of different html objects, such as tables, input fields and so on. You can see an example in the xsl listing.
P.S. I'm using xsl 1.0.
If you did a schema-aware XSLT 2.0 transformation, you wouldn't need all those type='xs:date' attributes: defining it in the schema as a date would be enough. You could then match the attributes with
<xsl:template match="attribute(*, xs:date)">
What you could do is add a template to match any element which has an #type attribute of 'xs:date', and do you substring manipulation in there
<xsl:template match="*[#type='xs:date']">
<xsl:value-of select="translate(., '-', '/')" />
</xsl:template>
In this case I am just replacing the hyphens by slashes as an example.
Then, instead of using xsl:value-of....
<div><xsl:value-of select="different-path/to_date"/></div>
You could use xsl:apply-templates
<div><xsl:apply-templates select="different-path/to_date"/></div>
Consider this XSLT as an example
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*[#type='xs:date']">
<xsl:copy>
<xsl:value-of select="translate(., '-', '/')" />
</xsl:copy>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
In this case, all this XSLT is doing is copying the XML document as-is, but changing the date elements.
If you wanted to use the date template for other elements, or values, you could also make it a named-template, like so
<xsl:template match="*[#type='xs:date']" name="date">
<xsl:param name="date" select="." />
<xsl:value-of select="translate($date, '-', '/')" />
</xsl:template>
This would allow you to also call it much like a function. For example, to format a data and add as an attribute you could do the following:
<input>
<xsl:attribute name="value">
<xsl:call-template name="date">
<xsl:with-param name="date" select="/select/a/date" />
</xsl:call-template>
</xsl:attribute>
</input>

XSLT matching PAGEID to an element ID

How would I match two separate numbers in an XML document? There are multiple <PgIndexElementInfo> elements in my XML document, each representing a different navigation element, each with a unique <ID>. Later in the document a <PageID> specifies a number that sometimes matches an <ID> used above. How could I go about matching the <PageID> to the <ID> specified above?
<Element>
<Content>
<PgIndexElementInfo>
<ElementData>
<Items>
<PgIndexElementItem>
<ID>1455917</ID>
</PgIndexElementItem>
</Items>
</ElementData>
</PgIndexElementInfo>
</Content>
</Element>
<Element>
<Content>
<CustomElementInfo>
<PageID>1455917</PageID>
</CustomElementInfo>
</Content>
</Element>
EDIT:
I added the solution below to my code. The xsl:apply-templates that is present is used to recreate the nested lists that are lost between HTML and XML. What I now need to do is match the PageID to the ID of a <PgIndexElementItem> and add a CSS class to the <ul> it is a part of. I hope that makes sense.
<xsl:key name="kIDByValue" match="ID" use="."/>
<xsl:template match="PageID[key('kIDByValue',.)]">
<xsl:apply-templates select="//PgIndexElementItem[not(contains(Description, '.'))]" />
</xsl:template>
<xsl:template match="PgIndexElementItem">
<li>
<xsl:value-of select="Title"/>
<xsl:variable name="prefix" select="concat(Description, '.')"/>
<xsl:variable name="childOptions"
select="../PgIndexElementItem[starts-with(Description, $prefix)
and not(contains(substring-after(Description, $prefix), '.'))]"/>
<xsl:if test="$childOptions">
<ul>
<xsl:apply-templates select="$childOptions" />
</ul>
</xsl:if>
</li>
</xsl:template>
The XSLT way for dealing with cross references is with keys.
Matching: A rule matching every PageID element that it has been referenced by an ID element.
<xsl:key name="kIDByValue" match="ID" use="."/>
<xsl:template match="PageID[key('kIDByValue',.)]">
<!-- Template content -->
</xsl:template>
Selecting: A expression selecting every PageID element with specific value.
<xsl:key name="kPageIDByValue" match="PageID" use="."/>
<xsl:template match="ID">
<xsl:apply-templates select="key('kPageIDByValue',.)"/>
</xsl:template>