2

I am using the following variable in php to handle a customer id:

$k='160177'

which I pass to my xslt using:

...
$xsl = $proc->importStylesheet($xsl);
$xsl = $proc->setParameter('', 'k', $k);
$newdom = $proc->transformToDoc($inputdom);
print $newdom->saveXML();

I pick up the variable in my XSLT and use it to check a node:

...
<xsl:apply-templates select="td:Globale_Pauschale[contains(td:CreatedBy, $k]">

This works fine BUT now I need to pass multiple customer ids via my php variable:

$k='160177,160176,160184,160178,160179....etc'

And get my XSLT contains statement to check against EACH customer id.

In PHP I would change my $k to an array and iterate through it but XSLT has no concept of an array. How do I get XSLT contains to check against EACH customer id ?

Mayn thanks for any help!!

2
  • Please give us an example of the content of td:CreatedBy. Is this single id? Commented May 27, 2013 at 15:02
  • td:CreatedBy is a single id stored in xml file. For example: 160177 Commented May 27, 2013 at 16:23

1 Answer 1

1

The only thing to do is to change the order of the contain function call to "td:Globale_Pauschale[contains($k,td:CreatedBy)]". Than you can have an list of ids in variable k ($k='160177,160176,160184,160178,160179').

But this will only work reliable if the ids have always the same length. (This will not work if you have also shorter ids like 16).

To make this work for ids with different length use the following select:

select="td:Globale_Pauschale[contains($k, 
            concat(',', normalize-space(td:CreatedBy), ','))]"

and put an comma at front and end of your variable k.
$k=',160177,160176,160184,160178,160179,16,'

Sign up to request clarification or add additional context in comments.

2 Comments

Great answer. Thanks. Works a treat!
@RichardTinkler: Glad I could help. Please consider to mark the answer as accepted. If you do not know how, have a look to FAQ.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.