Jump to content

Trouble Using Exslt:node-set() Function When Affecting Conditionned Variable Value


Guest haclong

Recommended Posts

Guest haclong

HelloBasically, i have this code

<xsl:template name="myTemplate"> <xsl:param name="newNodeSet"/> <!-- this is, of course, one node --> <xsl:param name="defaultNodeSet"/> <!-- this is another node --><xsl:variable name="myNodeToWorkWith"> <xsl:choose>   <xsl:when test="$newNodeSet"><xsl:value-of select="$newNodeSet"/></xsl:when>   <xsl:otherwise><xsl:value-of select="$defaultNodeSet"/></xsl:otherwise> </xsl:choose></xsl:variable><xsl:value-of select="exsl:node-set($myNodeToWorkWith)/Address[type='Business']/city"/></xsl:template>

this returns nothing.Of course, i have the exsl definition on my xsl:stylesheet node : xmlns:exsl="http://exslt.org/common"This should workI know this is working if the <xsl:variable> is actually using <xsl:element> but i want use the fragment tree result as is.Do you know if it is possible or i shouldn't waste my time searching again and again why the exsl:node-set is not understanding my xpath.FYI, the XML i need looks like this :

<Me>  <AddressBook>	 <Address>		<type>Business</type>		<street>street</street>		<zip>the zip code</zip>		<city>the city name</city>	  </Address>  </AddressBook></Me><You>  <AddressBook>	 <Address>		<type>Home</type>		<street>street</street>		<zip>the zip code</zip>		<city>the city name</city>	  </Address>	 <Address>		<type>Business</type>		<street>street</street>		<zip>the zip code</zip>		<city>the city name</city>	  </Address>  </AddressBook></You>

And i'll use my template this way

<xsl:call-template name="myTemplate"> <xsl:with-param name="newNodeSet" select="Me/AddressBook"/> <!-- this is, of course, one node --> <xsl:with-param name="defaultNodeSet" select="You/AddressBook"/> <!-- this is another node --></xsl:call-template>

Link to comment
Share on other sites

I think you may have to move your choose outside of the variable. exsl:node-set() only works on actual node sets. It signals they shouldn't be translated into scalar values before treatment. Once translated to scalars, they can't be rolled back to node sets.

<xsl:template name="myTemplate"><xsl:param name="newNodeSet"/> <!-- this is, of course, one node --><xsl:param name="defaultNodeSet"/> <!-- this is another node --><xsl:choose>   <xsl:when test="exsl:node-set($newNodeSet)">	  <xsl:value-of select="exsl:node-set($newNodeSet)/Address[type='Business']/city"/>   </xsl:when>   <xsl:otherwise>	  <xsl:call-template name="myTemplate">		 <xsl:with-param name="newNodeSet" select="exsl:node-set($defaultNodeSet)" />		 <xsl:with-param name="defaultNodeSet" select="exsl:node-set($defaultNodeSet)" />	  </xsl:call-template>   </xsl:otherwise></xsl:choose></xsl:template>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...