Find index of matches in xsl:analyze-string?
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 12
- Joined: Tue Nov 23, 2010 8:00 pm
Find index of matches in xsl:analyze-string?
Post by feickertmd »
I am using xsl:analyze-stirng to prse a long string and break it into separate lines that are under a given length.
Example input
I already have working code that gives me this:
... where the 10 character string is the result of xsl:nonmatching-substring.
What I need to get is this:
...where the position value corresponds to the index of the substring (i.e., the first matching substring is 1, the next is 2, and so on).
Need this soon, so ideas appreciated!!!
Example input
Code: Select all
<root>
<string>210 character string</string>
</root>
Code: Select all
<root>
<string>50 character string</string>
<string>50 character string</string>
<string>50 character string</string>
<string>50 character string</string>
<string>10 character string</string>
</root>
What I need to get is this:
Code: Select all
<root>
<string position="1">50 character string</string>
<string position="2">50 character string</string>
<string position="3">50 character string</string>
<string position="4">50 character string</string>
<string position="5">10 character string</string>
</root>
Need this soon, so ideas appreciated!!!
-
- Posts: 2881
- Joined: Tue May 17, 2005 4:01 pm
Re: Find index of matches in xsl:analyze-string?
Hi,
A simple idea is to collect all of them in a node-set variable and then iterate on the nodes from that for the position.
e.g.
The variable collects the actual matching substrings, but you can of course collect the already processed results (the string length).
Regards,
Adrian
A simple idea is to collect all of them in a node-set variable and then iterate on the nodes from that for the position.
e.g.
Code: Select all
<xsl:variable name="results">
<xsl:analyze-string select="text()" regex=".+">
<xsl:matching-substring>
<res><xsl:value-of select="."/></res>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:for-each select="$results/*">
<string position="{position()}"><xsl:value-of select="string-length(.)"/> character string</string>
</xsl:for-each>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ 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