string-length excluding child element content
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 156
- Joined: Sat Feb 26, 2005 12:09 am
- Location: USA
- Contact:
string-length excluding child element content
Post by shudson310 »
I'm trying to get the string length of an element, but need to exclude the children elements from the count.
Here is the test source:
I'm trying the following test:
the problem is that the descendant element content seems to be included in the count! The above should be valid, but it is getting flagged. How do I exclude the children from the string-length calculation?
Here is the test source:
Code: Select all
<indexterm>12345678901234567890123456789012
<index-see>bar
<indexterm>baz</indexterm>
</index-see>
</indexterm>
Code: Select all
<sch:assert test="string-length(text()[1]) <= 33" role="warning">
Scott Hudson
Staff Content Engineer
Site: docs.servicenow.com
Staff Content Engineer
Site: docs.servicenow.com
-
- Posts: 387
- Joined: Thu Jul 01, 2004 12:29 pm
Re: string-length excluding child element content
Hello,
The XPath expression that you used in the assertion excludes the children elements, but you need to exclude the whitespaces when you count the string length of the text node. For this you can use the "normalize-space()" function, something like:
Best Regards,
Octavian
The XPath expression that you used in the assertion excludes the children elements, but you need to exclude the whitespaces when you count the string length of the text node. For this you can use the "normalize-space()" function, something like:
Code: Select all
<sch:assert test="string-length(normalize-space(text()[1])) <= 33" role="warning">
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
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