tia_kamakshi
asked on
Pass xml node in xsl:template as parameter
Hi
How do we pass complete xml node in xsl:template as parameter
Like wise in below example I can pass string.
<xsl:template name="TextField">
<xsl:param name="questionID" />
<xsl:param name="value" />
<input type="text">
<xsl:attribute name="name">
<xsl:text disable-output-escaping="y es">questi on</xsl:te xt>
<xsl:value-of select="$questionID"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="$value" />
</xsl:attribute>
</input>
<br/>
</xsl:template>
How do we pass complete node to xsl:template
I wanted to create dopdown list from template
<select type="Dropdownlist">
<xsl:attribute name="name">
<xsl:text disable-output-escaping="y es">questi on</xsl:te xt>
<xsl:value-of select="../@questionID"/>
</xsl:attribute>
<xsl:for-each select="FieldValue/Option" >
<option>
<xsl:if test="@isSelected='True'">
<xsl:attribute name="Selected"/>
</xsl:if>
<xsl:attribute name="value">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:value-of select="." />
</option>
</xsl:for-each>
</select>
How do I pass Node FieldValue/Option (<xsl:for-each select="FieldValue/Option" >)
in template so that dropdown can be generated
Please Guide
Many Thanks
How do we pass complete xml node in xsl:template as parameter
Like wise in below example I can pass string.
<xsl:template name="TextField">
<xsl:param name="questionID" />
<xsl:param name="value" />
<input type="text">
<xsl:attribute name="name">
<xsl:text disable-output-escaping="y
<xsl:value-of select="$questionID"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="$value" />
</xsl:attribute>
</input>
<br/>
</xsl:template>
How do we pass complete node to xsl:template
I wanted to create dopdown list from template
<select type="Dropdownlist">
<xsl:attribute name="name">
<xsl:text disable-output-escaping="y
<xsl:value-of select="../@questionID"/>
</xsl:attribute>
<xsl:for-each select="FieldValue/Option"
<option>
<xsl:if test="@isSelected='True'">
<xsl:attribute name="Selected"/>
</xsl:if>
<xsl:attribute name="value">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:value-of select="." />
</option>
</xsl:for-each>
</select>
How do I pass Node FieldValue/Option (<xsl:for-each select="FieldValue/Option"
in template so that dropdown can be generated
Please Guide
Many Thanks
ASKER
Hi,
Thanks for your reply. I am transforming my XSL using ASP.net 3.5
I wanted to create dropdown from existing XML file. Please see my XSL snippet and Sample XML code
In my html file where I wanted to create text field, I call my template
<xsl:template name="TextField">
<xsl:param name="questionID" />
<xsl:param name="value" />
<input type="text">
<xsl:attribute name="name">
<xsl:text disable-output-escaping="y es">questi on</xsl:te xt>
<xsl:value-of select="$questionID"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="$value" />
</xsl:attribute>
</input>
<br/>
</xsl:template>
Like wise I wanted to create dropdown from xsl:template, Since in text field I have to pass only textfield name and value that's easy to pass single value.
But in dropdown I have to pass many options to add in dropdown
So, is it possible to pass a node in xsl:template param
Please see my XSL and XML
Please let me know if this is stil unclear
I don't know how to find which XSLT processor I am using
Please guide
Many Thanks
Thanks for your reply. I am transforming my XSL using ASP.net 3.5
I wanted to create dropdown from existing XML file. Please see my XSL snippet and Sample XML code
In my html file where I wanted to create text field, I call my template
<xsl:template name="TextField">
<xsl:param name="questionID" />
<xsl:param name="value" />
<input type="text">
<xsl:attribute name="name">
<xsl:text disable-output-escaping="y
<xsl:value-of select="$questionID"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="$value" />
</xsl:attribute>
</input>
<br/>
</xsl:template>
Like wise I wanted to create dropdown from xsl:template, Since in text field I have to pass only textfield name and value that's easy to pass single value.
But in dropdown I have to pass many options to add in dropdown
So, is it possible to pass a node in xsl:template param
Please see my XSL and XML
Please let me know if this is stil unclear
I don't know how to find which XSLT processor I am using
Please guide
Many Thanks
------------------ XSL SNIPPET--------------------------------
<xsl:if test="@type='Popup Menu'">
<xsl:for-each select="FieldValue">
<xsl:variable name="label-count" select="position()"/>
<tr>
<xsl:attribute name="id">
<xsl:text disable-output-escaping="yes">question_</xsl:text>
<xsl:value-of select="../../@questionID" />
<xsl:text disable-output-escaping="yes">_row_</xsl:text>
<xsl:value-of select="$label-count"/>
</xsl:attribute>
<xsl:if test="@visible='False'">
<xsl:attribute name="style">
<xsl:text disable-output-escaping="yes">display:none</xsl:text>
</xsl:attribute>
</xsl:if>
<td align="left">
<select type="Dropdownlist">
<xsl:attribute name="name">
<xsl:text disable-output-escaping="yes">question</xsl:text>
<xsl:value-of select="../../@questionID"/>
</xsl:attribute>
<xsl:for-each select="Option">
<option>
<xsl:if test="@isSelected='True'">
<xsl:attribute name="Selected"/>
</xsl:if>
<xsl:attribute name="value">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:value-of select="." />
</option>
</xsl:for-each>
</select>
</td>
<td>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
</td>
<td align="center">
<xsl:if test="../@canAddMoreControls='True'">
<xsl:call-template name="AddControls">
<xsl:with-param name="questionID">
<xsl:value-of select="../../@questionID"/>
</xsl:with-param>
<xsl:with-param name="label-count">
<xsl:value-of select="$label-count"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</td>
</tr>
</xsl:for-each>
</xsl:if>
------------------ XML SAMPLE --------------------------------
<?xml version="1.0" encoding="utf-8"?>
<TripDetails>
<TripSummary>
<TripID>2568</TripID>
</TripSummary>
<TripHeader name="Trip Details" orderNo="1">
<Label name="Grade Number" isRequired="True" helpingText="Level of difficulty from 1 to 10" questionID="60">
<Control type="Popup Menu" questionFormat="4" maxCount="1" displayCount="1" canAddMoreControls="False">
<FieldValue visible="True">
<Option id="30" isSelected="False"><![CDATA[1]]></Option>
<Option id="31" isSelected="False"><![CDATA[2]]></Option>
<Option id="32" isSelected="False"><![CDATA[3]]></Option>
<Option id="33" isSelected="False"><![CDATA[4]]></Option>
<Option id="34" isSelected="True"><![CDATA[5]]></Option>
<Option id="35" isSelected="False"><![CDATA[6]]></Option>
<Option id="36" isSelected="False"><![CDATA[7]]></Option>
<Option id="37" isSelected="False"><![CDATA[8]]></Option>
<Option id="38" isSelected="False"><![CDATA[9]]></Option>
<Option id="39" isSelected="False"><![CDATA[10]]></Option>
</FieldValue>
</Control>
</Label>
<Label name="Grade Text" isRequired="False" helpingText="Choose the trip grade from the list below (Utracks options are below the first 10)." questionID="91">
<Control type="Popup Menu" questionFormat="4" maxCount="1" displayCount="1" canAddMoreControls="False">
<FieldValue visible="True">
<Option id="48" isSelected="False"><![CDATA[1 - Discovery and Cruising level]]></Option>
<Option id="49" isSelected="False"><![CDATA[1 - Découverte et Croisière]]></Option>
<Option id="50" isSelected="False"><![CDATA[2 - Adventure touring level]]></Option>
<Option id="51" isSelected="False"><![CDATA[2 - Aventure]]></Option>
<Option id="52" isSelected="False"><![CDATA[3 - Introductory level]]></Option>
<Option id="53" isSelected="False"><![CDATA[3 - Introduction]]></Option>
<Option id="54" isSelected="False"><![CDATA[4 - Introductory to Moderate level]]></Option>
<Option id="55" isSelected="False"><![CDATA[4 - Introduction à Modéré]]></Option>
<Option id="56" isSelected="True"><![CDATA[5 - Moderate level]]></Option>
<Option id="57" isSelected="False"><![CDATA[5 - Modéré]]></Option>
<Option id="58" isSelected="False"><![CDATA[6 - Moderate to Challenging level]]></Option>
<Option id="59" isSelected="False"><![CDATA[6 - Modéré à Soutenu ]]></Option>
<Option id="60" isSelected="False"><![CDATA[7 - Challenging level]]></Option>
<Option id="61" isSelected="False"><![CDATA[7 - Soutenu]]></Option>
<Option id="62" isSelected="False"><![CDATA[8 - Entry level Mountaineering/Exploratory Trek]]></Option>
<Option id="63" isSelected="False"><![CDATA[8 - Alpinisme Initiation et Trek d'Exploration]]></Option>
<Option id="64" isSelected="False"><![CDATA[9 - Intermediate Mountaineering Expedition]]></Option>
<Option id="65" isSelected="False"><![CDATA[9 - Alpinisme Intermédiaire]]></Option>
<Option id="66" isSelected="False"><![CDATA[10 - Advanced Mountaineering Expedition]]></Option>
<Option id="67" isSelected="False"><![CDATA[10 - Alpinisme Avancé]]></Option>
<Option id="68" isSelected="False"><![CDATA[--Utracks choices are below!]]></Option>
<Option id="69" isSelected="False"><![CDATA[1 - introductory]]></Option>
<Option id="70" isSelected="False"><![CDATA[2 - introductory to moderate]]></Option>
<Option id="71" isSelected="False"><![CDATA[3 - moderate]]></Option>
<Option id="72" isSelected="False"><![CDATA[4 - moderate to challenging]]></Option>
<Option id="73" isSelected="False"><![CDATA[5 - challenging]]></Option>
</FieldValue>
</Control>
</Label>
</TripHeader>
</TripDetails>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Really Great.
Many Thanks
Many Thanks
welcome
If you want to pass an XML chunk that is allready existing (snippet from the source document)
you could simply do
<xsl:with-param name="value" select="FieldValue/Option"
If the Option is not part of an XML snippet that you just created,
you are dealing with a so called "Result Tree Fragment"
XSLT1 does not allow you to use XPath addressing in RTFs
but most processors have an extension "nodeset" that does that
So, for that you need to tell me what XSLT processor you are using
and I can help you with using the nodeset extension
After answering this, can you also be a bit more specific about what you want... your question is not 100% clear to me