I use the following XSLT code to extract a list of elements from another XML file:
<xsl:variable name="titleCodes" select="document('other_XML.xml')/list"/>
The other_XML.xml
file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="struktur_berufe.xsd">
<job id="15339" bkz="B 01104-101">
<type>t</type>
<name>
<name_nl>Job a</name_nl>
</name>
</job>
<job>
...
</job>
...
</list>
I now want to extract the id
attribute of the job
element, filtered by the name_nl
element. The value by which I filter is from the XML file I am trying to transform, which looks like this:
<JobPost>
<id>1</id>
<title>
Job a <!-- value I filter by -->
</title>
</JobPost>
Here's what I tried so far:
<TitleCode>
<xsl:value-of select="$titleCodes/job[type='t']/name[name_nl=title]/ancestor::job/@id"/>
</TitleCode>
However, the problem seems to be, that [name_nl=title]
is empty, since it looks for thetitle
element in the other_XML.xml
, which it of course doesn't have.
I also tried using a variable like this:
<TitleCode>
<xsl:variable select="title" name="ab"/>
<xsl:value-of select="$titleCodes/job[type='t']/name[name_nl=$ab]/ancestor::job/@id"/>
</TitleCode>
But that still return ''
.
So is there any way to solve this problem?