[xsl] Using multiple values stored in a variable

Subject: [xsl] Using multiple values stored in a variable
From: Manuel Souto Pico <m.soutopico@xxxxxxxxx>
Date: Sun, 6 Jan 2013 19:13:01 +0000
Hi there,

I've been stuck for a couple of days with a failing transformation, I
hope any one can help me out. Thank you very much in advance.

I have an external XML document that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
    <entry id="2">

That's a glossary that I use to proces the main XML document. I get it
like this:

<xsl:variable name="glossary" select=

For each entry in the glossary, I need to check whether ANY of the
terms (under target) is found in a string element of the main

If there was only one term element under each target, it would be easy
to capture:

<xsl:variable name="target-term" select="../../target/term[normalize-space()]"/>

But since there might be any number of terms, I think I need to use
something like this (which seems to work):

<xsl:variable name="target-term" as="element()*"

Then, for the actual check, this would work if there was only one
term, but if fails for the multiple valued variable that I have:

<xsl:when test="matches(string, $target-term, 'i')">

I get error XPTY0004: A sequence of more than one item is not allowed
as the second argument of
  matches() ("acceso", "ingreso")

The wrong bit should be the $target-term, but I don't know how to
write in order to check the mutiple values one by one.

Although I think I've given all the necessary details, the full
stylesheet is below if case you want to have a wider context or
improve anything (probably some of the recursions are unnecessary, and
the processing is slow):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    <xsl:output method="text"/>

    <xsl:template match="/">

        <xsl:variable name="glossary" select=

        <xsl:for-each select="xliff//trans-unit/source">
            <xsl:variable name="source-segment" select="."/>
            <xsl:variable name="target-segment" select="../target"/>
            <xsl:for-each select="$glossary//source/term">
                <xsl:variable name="source-term" select="."/>
                <xsl:variable name="target-term" as="element()*"
                <xsl:if test="matches($source-segment, $source-term, 'i')">
                        <xsl:when test="matches($target-segment,
$target-term, 'i')">
                            <xsl:text>Term found.</xsl:text>
                            <xsl:text>Term not found.</xsl:text>


Thanks a lot!

Cheers, Manuel

Current Thread