Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please help .. nested element trouble in XSL 1

Status
Not open for further replies.

kibje

Technical User
May 19, 2003
13
0
0
NL
Hi all,

i am running into problems with XSL where I want to be able to nest xml elements in my schema like this:

<xs:element name=&quot;text&quot;>
<xs:complexType mixed=&quot;true&quot;>
<xs:all minOccurs=&quot;0&quot;>
<xs:element name=&quot;bold&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot;/>
</xs:all>
</xs:complexType>
</xs:element>


an example being:
<text>this is a sample text with a <bold>bold</bold> word in it</text>

this should be translated to

this is a sample text with a bold word in it

but i don't seem to get my xsl right.
At the moment i tried a few things, the most effective being

<xsl:when test=&quot;text/bold&quot;>
<xsl:value-of select=&quot;text&quot;></xsl:value-of><b><xsl:value-of select=&quot;text/bold&quot;></xsl:value-of></b>
</xsl:when>


which results in
this is a sample text with a bold word in itbold

i am totally at a los at this moment.
all the other hard things (like automatic numbering, index building, image lists, in-document linking etc) i had to do i finished well ahead of time, but this tiny thing I can't seem to finish.
 
Maybe this can help?
I ran this xsl:
Code:
<xsl:template match=&quot;/&quot;>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match=&quot;*&quot;/>

<xsl:template match=&quot;root&quot;>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match=&quot;text&quot;>
  <some-html-tags>
  <xsl:apply-templates/>
  </some-html-tags>
</xsl:template>

<xsl:template match=&quot;bold&quot;>
  <b><xsl:apply-templates/></b>
</xsl:template>

on this xml:
Code:
<root>
  <text>This is a <bold>bold</bold> word.</text>
  <something-else>this should not be parsed</something-else>
  <text>And <bold>this</bold> is too</text>
  <something-else>this should not be parsed</something-else>
  <text>But this is not</text>
</root>

And it seemed to be OK.
 
Oh for the lords .. I had this EXACTLY as you typed it in an earlier version but it didn't work there. I immediately thought my reasoning must have been wrong at that time and after reading your reply I thought

'Well that won't work I tried that.'

So I kept reading the XML Bible, and some other manuals I have laying around here until my eye caught a sentence about later instructions in an xsl being referenced first.

I checked back on my code and behold ...

I had it listed EXACTLY like you typed, only i had put it EXACTLY the other way around ...
try replacing

<xsl:template match=&quot;text&quot;>
<some-html-tags>
<xsl:apply-templates/>
</some-html-tags>
</xsl:template>

<xsl:template match=&quot;bold&quot;>
<b><xsl:apply-templates/></b>
</xsl:template>

with

<xsl:template match=&quot;bold&quot;>
<b><xsl:apply-templates/></b>
</xsl:template>

<xsl:template match=&quot;text&quot;>
<some-html-tags>
<xsl:apply-templates/>
</some-html-tags>
</xsl:template>

You will see it won't work. I know this is a beginners mistake but after all i AM a beginner :) I managed a lot in the last 3 weeks though in XML.

Thanks for showing me the light :)
I feel so stupid doing all these difficult tasks in XML without problems, then making a totally newbie mistake on an easy thing....
 
Same here...

<xsl:template-match> is rather an essential element in xsl, and the both of us still don't seem to understand all about it.
:(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top