How can I set an a href that is both a link to and has the text for a link through an XSLT transformation? Here's what I have so far, which gives me the error "xsl:value-of cannot be a child of the xsl:text element":
<xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="actionUrl"/> </xsl:attribute> <xsl:text><xsl:value-of select="actionUrl"/></xsl:text> </xsl:element>
XSLT <xsl:variable>The <xsl:variable> element is used to declare a local or global variable. Note: The variable is global if it's declared as a top-level element, and local if it's declared within a template. Note: Once you have set a variable's value, you cannot change or modify that value!
XSLT doesn't do hyperlinks. Rethink your question. When thinking about how to achieve something like this in XSLT, split the task into two: (a) decide what HTML you want to generate, and (b) decide what XSLT code you need in order to generate it.
XSLT <xsl:text> The <xsl:text> element is used to write literal text to the output. Tip: This element may contain literal text, entity references, and #PCDATA.
Variables in XSLT are not really variables, as their values cannot be changed. They resemble constants from conventional programming languages. The only way in which a variable can be changed is by declaring it inside a for-each loop, in which case its value will be updated for every iteration.
<xsl:text>
defines a text section in an XSL document. Only real, plain text can go here, and not XML nodes. You only need <xsl:value-of select="actionUrl"/>
, which will print text anyways.
<xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="actionUrl"/> </xsl:attribute> <xsl:value-of select="actionUrl"/> </xsl:element>
You can also do:
<a href="{actionUrl}"><xsl:value-of select="actionUrl"/></a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With