0

I'm trying to assign a dynamic generated XML to a xsl variable and from there I want to loop over it. But I never get any info or result from the loop. So I tried to add the XML manually in the xslt file like this to show you what I'm expecting or trying to work with:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:php="http://php.net/xsl">

    <xsl:output method="text" encoding="utf-8" />

    <xsl:variable name="websites">
    <SHOP><WEBSITE><STORE_VIEW_CODE>ca_en</STORE_VIEW_CODE><LANGUAGE>en</LANGUAGE></WEBSITE><WEBSITE><STORE_VIEW_CODE>nl_nl</STORE_VIEW_CODE><LANGUAGE>nl</LANGUAGE></WEBSITE></SHOP>
    </xsl:variable>

    <xsl:template match="/">
        <xsl:for-each select="$websites">
            <xsl:apply-templates select="WEBSITE"/>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="WEBSITE">
        <xsl:text>FOUND SOMETHING</xsl:text>
    </xsl:template>

But there is nothing coming back from that loop. I can use value-of and select the website variable then I see the whole content but I would like to loop through the nodes to extract the text.

UPDATE The two answers with node-set and the link for more details solved my problem.

Timo.Klement
  • 655
  • 1
  • 11
  • 31
  • 1
    In XSLT 1.0, you have to convert result tree fragments to node sets. Try using the node-set function to convert $websites to a node set. – John Ernst Jul 10 '20 at 02:09
  • 2
    Does this help answer your question? https://stackoverflow.com/questions/3880499/create-node-set-and-pass-as-a-parameter – Xavier Dass Jul 10 '20 at 07:17
  • Thank you both. I understand now and I can reproduce and solve my problem on http://xsltransform.net/ but I get nothing on my local machine. The same small code is working but conversions seems not to work. I don't get any errors. – Timo.Klement Jul 10 '20 at 11:04
  • Awesome it is working, my fault. I had the same match several pages later. :-) – Timo.Klement Jul 10 '20 at 11:06

0 Answers0