Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes XSLT and embedded tags in text. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT and embedded tags in text." Watch "XSLT and embedded tags in text." New topic

XSLT and embedded tags in text.

Heath Lilley
Ranch Hand

Joined: Jan 09, 2001
Posts: 72
I am having a problem with XSLT and I was hoping that you could shed some light on it.
I have a line of text I am referencing in a XML document...

I have been able to find this node via a template AND I can identify the input_text tag as well. What I want to do is replace the input_text tag with a real HTML tag. I am doing this like so...
Find/output the substring before the tag.
Then, output the html input element in place of the tag.
And finally, output the substring after the tag.
The xslt code in question.

The above template defined.

I looked at the xpath functions and I know I can't use the < or > brackets, I tried escaping the brackets < and > but it isn't associating the tag bracets with the codes.
My above code will NOT output any of the substrings. It does output a textbox though.
Am I trying to do something that xslt can't do? Any help would be greatly appreciated.
Thank you for your time.
[ October 22, 2003: Message edited by: Heath Lilley ]
Tony Yan
Ranch Hand

Joined: Apr 10, 2002
Posts: 170
I think the problem is that text() will only give you the text value, so that the substring function will not even find the <, however you define it. the value of text() of <xyz/> is empty, I believe.
Maybe you should try to get all the nodes by combining * and text()? and then go thru each node, if a node has a local-name() is input_text, then insert your html code. In this way, you avoid using substring() etc, which is not that reliable in case that you add more nodes in.
Hope it helps.

Tony Yan<br /> <br />IBM Certified Developer XML and Related Technology<br />Sun Certified Web Component Developer For J2EE Platform<br />Sun Certified Programmer For Java 2 Platform
Tony Yan
Ranch Hand

Joined: Apr 10, 2002
Posts: 170
Try this, it will give you a good idea on how the text() and * work. You can derive from this to get a solution, I hope.

Heath Lilley
Ranch Hand

Joined: Jan 09, 2001
Posts: 72
Thank you for the responses. I think I figured it out. I forget where I read it but it seems that text() only returns the text between the start element and the next element NOT the matching ending element.
I have access to changing the xml schema structure so what we did was and another set of element tags to separate the plain text from any embedded tags.

I was oringinally hoping to avoid this but I don't think it was possible.

This allows me to get the text and the input element in the xslt.
I agree. Here's the link:
subject: XSLT and embedded tags in text.
Similar Threads
XSLT value-of parameter not works as xml value
XSL distinct values
convert &amp;amp; to &
problem with xsl:template and xsl:call-template
xsl template question