tags:

views:

65

answers:

1
<xsl:template name="ClickPIB">
  <xsl:param name="abc" />
  <xsl:param name="xyz" />
  <xsl:if test="string-length($abc) &gt; 0">

   <script type="text/javascript">

$(document).ready(function () {
 $('#<xsl:value-of select="concat($abc, '_td')"/>').getXYZ("<xsl:value-of select="concat(substring-before($abc,'_'), '_landreover_', substring-after($xyz,'PXN'))"/>"); 
});

</script>
  </xsl:if>
</xsl:template>

The above works fine....

<xsl:template name="ClickPIB">
  <xsl:param name="abc" />
  <xsl:param name="xyz" />
  <xsl:if test="string-length($abc) &gt; 0">

   <script type="text/javascript">

$(document).ready(function () {
 $('#<xsl:value-of select="concat($abc, '_td')"/>').getXYZ("{concat($abc, 'blahblah')}", "<xsl:value-of select="concat(substring-before($abc,'_'), '_landreover_', substring-after($xyz,'PXN'))"/>"); 
});

</script>
  </xsl:if>
</xsl:template>

The above doesn't, the only thing I added was the "{concat($abc, 'blahblah')}" and this is the part that doesn't get interpolated with the value.

WHY? OH WHY!?

+3  A: 

Because attribute value templates (the expressions in curly brackets) do not get evaluated everywhere, but only in attributes (hence the name). Use:

<xsl:value-of select="concat($abc, 'blahblah')" />

just like you do in the other spots you want to write values to the output.

For increased code clarity, I'd recommend using variables:

<xsl:template name="ClickPIB">
  <xsl:param name="abc" />
  <xsl:param name="xyz" />
  <xsl:if test="string-length($abc) &gt; 0">
    <xsl:variable name="vSelector" select="concat($abc, '_td')" />
    <xsl:variable name="vArgument" select="concat(substring-before($abc,'_'), '_landreover_', substring-after($xyz,'PXN'))" />

     <script type="text/javascript">
       $(document).ready(function () {
         $('#<xsl:value-of select="$vSelector"/>').getXYZ("<xsl:value-of select="$vArgument"/>"); 
       });
     </script>
  </xsl:if>
</xsl:template>
Tomalak
thanks, I just realized something profound in life. XSLT cannot be done between 3AM-9AM. It's the only development language I have been unable to code in during these hours, and just moments later it works.I had almost verbatim the same code you did, I tried the <xsl value select of thing> ... but I "forgot" the /> at the end, and beat my head against the wall ... so glad I copied and pasted your code to see it work, and realize my mistake.thanks.
halivingston
+1 for one more clean and working code ..
infant programmer