Want to do some parsing/modification of the text contents of a node if all that text()
returns is a pure text string. No XML inside.
For example
<test>some <super>1</super> text here</test>
text()
for <test>
returns just "some ". This is a case where I do not want to output the text and instead want to call apply-templates.
Is there anyway to tell or is this situation too ambiguous for XSL to handle?
Edit: The output I want is exactly this
Reasoning is this: Sometimes there is just text that has a word split by a "/". I want to add spaces before and after so it's " / " instead. But sometimes the same node has xML in it.
some <super>1</super> text here
The test or predicate
count(text()) = count(node())
should work to make the distinction.Actually in the situation described, text() returns a sequence of two text nodes, "some " and " text here", but in XSLT 1.0, many operations on a sequence (or set) of nodes ignore all nodes except the first.
You haven't said what output you want. But the usual way of processing mixed content is to call apply-templates to process all the children. Explicit use of text() is very rarely the right thing to do.
This stylesheet:
With this input:
Output:
Note: One way (another would be with modes) for also splitting descendant is to use
test//text()
as pattern.You can test to see if the current node has children: