Tag Layout

Al

Usenet Archive
Joined
Mar 29, 2000
Messages
343
Reaction score
0
I wrote a C tutorial that I covert to XML.

<tutorial>
<section id="1">
<title>Data Types</title>

<section id="1.1">
<title>Numeric Types</title>

<content>
Lots of Text......

<code_block>Some Example Code</code_block>

More Text...

</content>
</section>
 

Andy Dingley

Usenet Archive
Joined
Feb 23, 2000
Messages
3,303
Reaction score
0
<content>
Lots of Text......

<code_block>Some Example Code</code_block>

More Text...

</content>
I am trying to set it up so the formatted <code_block> outputs after "Lots of text..." and before "More Text...".
Is there a better way to set up my XML file or is it my XSL?

You _could_ fix this in XSL, but it's really awkward. Avoid "mixed content" models like this - they're troublesome.

Try this instead:

<content>

<p>
Lots of Text......
</p>

<code_block>Some Example Code</code_block>

<p>
More Text...
</p>

</content>

Or even better, look into the DocBook DTD. There are even pre-written XSL stylesheets for it.
 

C. M. Sperberg-McQueen

Usenet Archive
Joined
Jul 2, 2003
Messages
95
Reaction score
0
Al said:
I wrote a C tutorial that I covert to XML.

...
<content>
Lots of Text......

<code_block>Some Example Code</code_block>

More Text...

</content>
...
... The problem is the
<xsl:value-of select="."/> ( . is the <content> node) includes the <code_block> values in the <content> value.

Yep, that's your problem, all right.
Is there a better way to set up my XML file or is it my XSL?

Your XML is fine. (Some people will tell you that you should avoid mixed content; when your schema is for documents, as opposed to database records, these people are, ah, wrong.)

If I were you, I'd change
<xsl:template match="content">

<xsl:element name="div">

<xsl:value-of select="." />
<xsl:apply-templates select="code_block"/>

</xsl:element>

</xsl:template>

to

<xsl:template match="content">
<xsl:element name="div">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

Since the default for apply-templates is to select the
child nodes of the current node, you'll get the initial text node, followed by the code block, followed by the final text node. One rule for processing mixed content is to let your data drive the stylesheet and not try to control everything using manual selects.

I hope this helps.

-C. M. Sperberg-McQueen
World Wide Web Consortium
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top