Reputation: 33
I'm looking for a simpler way to concatenate a variable and a string value. Currently I have the following:
<xsl:for-each select="$var_asset_name">
<xsl:attribute name="Asset_Name" select="fn:concat(fn:string(.), '_title')"/>
</xsl:for-each>
with $var_asset_name defined further up. This works, but I'm wondering if there is a simpler way to achieve the same result. I have tried
<xsl:attribute name="Asset_Name" select="fn:concat($var_asset_name, '_title')"/>
but it did not work (Error: The supplied sequence ('2' item(s)) has the wrong occurrence to match the sequence type xs:anyAtomicType ('zero or one'))
Thanks in advance.
Upvotes: 2
Views: 17113
Reputation: 1882
At the moment, all XPath versions have a string concatenation function, not a string concatenation operator: XPath 1.0, XPath 2.0, XPath 3.1
Upvotes: 0
Reputation: 5432
With this input:
<root/>
The following XSLT(which uses attribute value template):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="var_asset_name">stack</xsl:variable>
<xsl:template match="root">
<root Asset_Name="{$var_asset_name}_overflow"/>
</xsl:template>
</xsl:stylesheet>
Would produce:
<?xml version="1.0" encoding="utf-8"?>
<root Asset_Name="stack_overflow"/>
I hope you wanted an easier way to create attributes.
Upvotes: 2