views:

327

answers:

2

I have an XSLT function that takes a regular expression as a parameter but the XSLT parser does not like it.

Here is the code:

<xsl:value-of select='ns:RegexReplace($variable, "", "style=\"\w+\:\s\w+;\"")' disable-output-escaping='yes' />

I found this: http://www.xml.com/pub/a/2003/06/04/tr.html <-- but it is using what I am and seems to work (for them). Do I just have a rubbish parser??

Is there any way of doing this? Or, a way of forcing an element to ignore inline style via a CSS trick?

+2  A: 

You seem to be trying to include quotes in a quote-delimited XPath string literal by escaping them with a backslash. That does not work.

In XPath 1.0 (XSLT 1), there is no nice way to do this. You may need to resort to tricks like defining a variable which holds a single quote character and using the concat function to create your string:

<xsl:variable name='quot' select="'&quot;'"/>
<xsl:value-of select='concat("a string with a quote ", $quot, " character")'/>

In XPath 2.0 (XSLT 2), you can escape a quote with another quote:

<xsl:value-of select='"a string with a quote "" character"'/>
Jukka Matilainen
A: 

It occurs to me that you may be trying to remove style attributes. If that is the case, then string replacement is not going to help you.

You can remove style attributes for example by writing a template which matches them and outputs nothing:

<xsl:template match="@style"/>
Jukka Matilainen
Unfortunately, there is a function that returns the inline style as text and hence cannot be removed this way.
tgandrews