Passing formatted data into an attribute
Posted: Fri Apr 21, 2006 12:43 am
I am fairly new to XSLT, so this may be simpler than I think.
I need to pass some formatted data into a function to display as a popup when the user hovers over a link element. I have a vendor, price and date that I want formatted as “from x for $9.99 on m/d/yyyyâ€.
I have templates set up to handle the formatting (price is ignored if the purchase price is not a positive number, for instance) but I cannot figure out how to get it passed to the function, because no matter what I do I eventually have to use an XSLT transform to get the data into the link. I am using it earlier in the document for raw (unformatted) data. This is the code that works:
<xsl:variable name="width" select="string-length(concat('ID:', '@ID'))" />
<a onMouseout="hideddrivetip()">
<xsl:attribute name="onMouseover">
<xsl:value-of select='concat("ddrivetip(", @ID , ", ", $width , ")")' />
</xsl:attribute>
<xsl:value-of select="Subject/Manufacturer" /><![CDATA[ ]]>
<xsl:value-of select="Subject/Name" />
</a>
That works because the @ID variable is simple and doesn't require formatting. To do the other tip, I need to create a variable to store the templates formatted data (datext) and use it to pass the data to the attribute creation.
<xsl:variable name="datext" select='concat("../../Purchase/Vendor", apply-templates("../../Purchase/Price"), apply-templates("../../Purchase/Date")' />
<xsl:variable name="width2" select="string-length($datext)" />
<a onMouseout="hideddrivetip()">
<xsl:attribute name="onMouseover">
<xsl:value-of select='concat("ddrivetip(", $datext , ", ", $width2 , ")")' />
</xsl:attribute>
<xsl:value-of select="../../Brand" /><![CDATA[ ]]>
<xsl:value-of select="../../Type" /><![CDATA[ ]]>
<xsl:value-of select="../../Note" />
</a>
Obviously, the first line doesn't work – I know that. But that's essentially what I need to do before passing the resulting data into the “onMouseover†command.
I cannot for the life of me figure out any way of doing this. I can't get the formatted text into the datext storage variable. Is it even possible?
I'm hoping it is and that someone can help. Thanks in advance.
I need to pass some formatted data into a function to display as a popup when the user hovers over a link element. I have a vendor, price and date that I want formatted as “from x for $9.99 on m/d/yyyyâ€.
I have templates set up to handle the formatting (price is ignored if the purchase price is not a positive number, for instance) but I cannot figure out how to get it passed to the function, because no matter what I do I eventually have to use an XSLT transform to get the data into the link. I am using it earlier in the document for raw (unformatted) data. This is the code that works:
<xsl:variable name="width" select="string-length(concat('ID:', '@ID'))" />
<a onMouseout="hideddrivetip()">
<xsl:attribute name="onMouseover">
<xsl:value-of select='concat("ddrivetip(", @ID , ", ", $width , ")")' />
</xsl:attribute>
<xsl:value-of select="Subject/Manufacturer" /><![CDATA[ ]]>
<xsl:value-of select="Subject/Name" />
</a>
That works because the @ID variable is simple and doesn't require formatting. To do the other tip, I need to create a variable to store the templates formatted data (datext) and use it to pass the data to the attribute creation.
<xsl:variable name="datext" select='concat("../../Purchase/Vendor", apply-templates("../../Purchase/Price"), apply-templates("../../Purchase/Date")' />
<xsl:variable name="width2" select="string-length($datext)" />
<a onMouseout="hideddrivetip()">
<xsl:attribute name="onMouseover">
<xsl:value-of select='concat("ddrivetip(", $datext , ", ", $width2 , ")")' />
</xsl:attribute>
<xsl:value-of select="../../Brand" /><![CDATA[ ]]>
<xsl:value-of select="../../Type" /><![CDATA[ ]]>
<xsl:value-of select="../../Note" />
</a>
Obviously, the first line doesn't work – I know that. But that's essentially what I need to do before passing the resulting data into the “onMouseover†command.
I cannot for the life of me figure out any way of doing this. I can't get the formatted text into the datext storage variable. Is it even possible?
I'm hoping it is and that someone can help. Thanks in advance.