[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Regular expression functions (Was: Re: comments on
David, > <xsl:apply-regexp-templates-to-string select="text()"/> > > ... > > <xsl:regexp-template match="\sqrt{([^{}]*)}"> > <msqrt> > <xsl:apply-regexp-templates-to-string select="$1"/> > </msqrt> > </xsl:regexp-template> > > <xsl:regexp-template match="\gamma"> > <mi>γ</mi> > </xsl:regexp-template> Ooh, tasty... Presumably the match patterns would match the entire string? So to do the whitespace replacement stuff that I mentioned, you'd have: <xsl:regexp-template match="([^
	
]*)([
	
])(.*)"> <xsl:value-of select="$1" /> <xsl:value-of select="if ($2 = '
') then '\n' else if ($2 = '	') then '\t' else if ($2 = '
') then '\r'" /> <xsl:apply-regexp-templates-to-string select="$3" /> </xsl:regexp-template> The big weakness if this was the *only* method of doing matches is that you can't use it with dynamic regular expressions - for example match strings that contain the keyword $keyword as a word. Any ideas around that one? On a kind of related topic, I did wonder whether XSLT 2.0 would support templates that matched things other than nodes (but it seems not). It occurred to me that this could be useful if, for example, you wanted all your numbers to be formatted in the same way throughout the document - you could have: <xsl:template match="value of type xs:decimal"> <xsl:value-of select="format-number(., '#,##0.00')" /> </xsl:template> [Note slight adjustment to the syntax for specifying datatypes, to avoid confusion with element names.] and then apply templates to whatever values wherever you found them (even if they were found via substring or in sequences or whatever). If there were string-regexp templates and not general value-matching templates, then people might be tempted to use regular expressions to identify data types in their match patterns instead. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|