Regex + XSLT 2.0 problem
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 14
- Joined: Wed Sep 20, 2006 7:07 pm
Regex + XSLT 2.0 problem
Post by heavydawson »
I have some text I'd like to format, and need to use regex + xslt 2.0 do do it.
What I have is a list of items in the following format:
"xxxxxx\xxxxx\xxxxxxx\xxxx\abcd.java"
I need to remove everything except "abcd".
I'm a complete Regex novice, and even got my hands on a copy of Regex Buddy to help me out, but apparently the Regex implementation in XSLT does not quite implement the full PERL standard.
Can anyone help me out?
What I have is a list of items in the following format:
"xxxxxx\xxxxx\xxxxxxx\xxxx\abcd.java"
I need to remove everything except "abcd".
I'm a complete Regex novice, and even got my hands on a copy of Regex Buddy to help me out, but apparently the Regex implementation in XSLT does not quite implement the full PERL standard.
Can anyone help me out?
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post by sorin_ristache »
Hello,
You should use the xsl:analyze-string element. Look at the regex attribute. The output of the following stylesheet:
is
You can read about matching a regex in XSLT 2.0 here.
Regards,
Sorin
You should use the xsl:analyze-string element. Look at the regex attribute. The output of the following stylesheet:
Code: Select all
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/">
<xsl:variable name="text" select="'xxxxxx\xxxxx\xxxxxxx\xxxx\abcd.java'"/>
<xsl:analyze-string select="$text" regex="(.*)\\(.*).java">
<xsl:matching-substring>
<javaClass name="{regex-group(2)}"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<javaClass name="abcd"/>
Regards,
Sorin
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service