|
 |
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |

June 13th, 2007, 04:29 PM
|
Authorized User
|
|
Join Date: Jun 2007
Location: , , .
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
Points: 18,487, Level: 59 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Location: , , .
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
Points: 18,487, Level: 59 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Location: , , .
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
Points: 18,487, Level: 59 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |