slopeman
slopeman

Reputation: 15

concat removing xml tags

I'm trying to concatenate some data together using the concat function in XSL. Most of the items are simple string values but one of the items is a snippet of some XML. What I'm seeing is that when concatenating the data together, the XML tags are being removed. Is this to be expected? Is there a way to work around this?

Below is my concat statement that I'm putting in a variable:

<xsl:variable name="hashKeyString"><xsl:copy-of select="concat(14,1269,Wire,ABC,<tag1>123</tag1>,XYZ)"/></xsl:variable>

When I look at the variable contents, I see "141269WireABC123XYZ". The tags are gone.

Any help or insight would be appreciated.

UPDATE: As many have noted, this example is not great. In my haste to put this in, I probably didn't give a great example. The values that are listed in the above example to be concatenated are actually data that are in variables. My main problem is that one of the variables contains XML. If I look at the variable contents, the tags are there. After using the variable in the concat statement, the tags are no longer there. I'm looking for a way to keep the XML tags as part of the concatenation of the data. What I see after the concat statement is essentially "value-of" results of what used to be XML.

Upvotes: 1

Views: 130

Answers (2)

Filburt
Filburt

Reputation: 18061

While I doubt that your actual task involves concatenating hard coded values, you can achieve the desired result putting your values in quotes and replace the offending entities by their character value:

<xsl:value-of select="concat('14','1269','Wire','ABC','&#60;tag1&#62;123&#60;/tag1&#62;','XYZ')" />

However this is merely because-it-can-be-done ... your actual task surely will require a solution like the one presented by @michael.

Upvotes: 1

michael.hor257k
michael.hor257k

Reputation: 116993

It seems strange that you would want to have mixed content in a variable, but if you really need it, try:

<xsl:value-of select="concat(14,1269,Wire,ABC)"/>
<tag1>123</tag1>
<xsl:value-of select="XYZ"/>

Note that concat(14,1269) is always 141269, so the first comma is redundant.

Upvotes: 2

Related Questions