|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
June 13th, 2007, 04:29 PM
|
Authorized User
|
|
Join Date: Jun 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
String manipulation
Is there a better/more efficient way to convert:
Projects\Documents (...regex...)
TO
Projects\\Documents (...regex...)
<xsl:template name="escape_backslash">
<xsl:param name="in"/>
<xsl:param name="out"/>
<xsl:choose>
<xsl:when test="contains($in, '\')">
<xsl:call-template name="escape_backslash">
<xsl:with-param name="in" select="substring-after($in, '\')"/>
<xsl:with-param name="out" select="concat($out, substring-before($in, '\'), '\\')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($out, $in)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
|
June 13th, 2007, 05:04 PM
|
|
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Unless you move to XSLT 2.0, you're stuck with this kind of approach.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
June 13th, 2007, 05:33 PM
|
Authorized User
|
|
Join Date: Jun 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry, should rephrased question. Is there a more efficient way to do this in XSLT 2.0? I am using Saxon8.
|
June 13th, 2007, 05:41 PM
|
|
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
In XSLT 2.0 it's
replace($in, '\\', '\\\\')
(in both the regex and the replacement string, a backslash is written as '\\')
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
June 14th, 2007, 09:25 AM
|
Authorized User
|
|
Join Date: Jun 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Does it cost additional processing time if I defined it as a function and call it?
pc:escapeBackslash($path)
<xsl:function name="pc:escapeBackslash">
<xsl:param name="$in"/>
<xsl:sequence select="replace($in, '\\', '\\\\')"/>
</xsl:function>
|
June 14th, 2007, 10:32 AM
|
|
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Depends on your processor. Measure it and see. With a good optimizer, functions like that are likely to generate inline code.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
|