Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP array into xslt

Status
Not open for further replies.

joseppic

Programmer
Nov 21, 2002
7
GB
I would like to pass a list of data I have in a php array into my xslt so that I can compare elements of the array with a sequence of XML (this is actually so I can have a DDLB which has some selected elements in it).

On the xslt side, can it handle such a variable as an xsl:param?

How do I access the individual elements/traverse the array?
What would the xsl:for-each look like?

Should I encode the array into XML and add it to my XML string and get it into the xslt that way?
Thanks,

Joseppic.
 
Ok,

How I fixed this was I put my array of fesults into a string and passed that in.

During my xslt I test the string using the contains(value, substring) to find it in the string.

HTH
 

Hi Joseppic,

I'm facing the same situation. Could you provide an example of how you fixed this problem?

Also, just more information about my case, I'm using C# to pass the array or variables to the XSLT.

Thanks a lot.

Peter.
 
OK,

Within my Php, I have a standard xslTranslator() method which takes in:
- The XML (string datatype, in my case the possible values of a DDLB)
- The filename.xsl (the XSLTemplate for the XML, in my case the iteration to embed the above values into a DDLB)
- A Params Array (external parameters which will also affect the XSLT but are not part of the pure XML, in my case, a csv string which lists the values previously selected in a multiple DDLB).

Params are a standard way of passing data to XSLT but they do not handle Arrays. So, I collapsed my array into a csv string so it could be passed as a single Param.

The inportant XSL command is the 'contains' which checks my parameter string.


Here's an example snippet:


<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl=" version="1.0">
<xsl:param name='lostofnumbersParamString' select="'aDefaultValueNotUsed'"/>
<xsl:template match='/'>
<table>
<tr>
<td align='left'>
<xsl:apply-templates select='listofnumbers'></xsl:apply-templates>
</td>
</tr>
</table>
</xsl:template>

<xsl:template match='listofnumbers'>
<xsl:call-template name='numbersDDLB'/>
</xsl:template>

<xsl:template name="numbersDDLB">
<select name='numbersSelected[]' id='numbersSelected'>
<xsl:attribute name='size'>5</xsl:attribute>
<xsl:attribute name='multiple'>multiple</xsl:attribute>
<xsl:for-each select="xmlNumberSeq">
<xsl:sort/>
<option>
<xsl:if test="contains($lostofnumbersParamString, @anXmlNumber)">
<xsl:attribute name='selected'>selected</xsl:attribute>
</xsl:if>
<xsl:attribute name='value'><xsl:value-of select='@anXmlNumber'/></xsl:attribute>
<xsl:value-of select='@anXmlNumber'/>
</option>
</xsl:for-each>
</select>
</xsl:template>
</xsl:stylesheet>



Hope this helps,

Joseppic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top