Hi Jerome,

For generic XSLT questions, I always recommend users subcribe and post to
the Mulberry Technologies XSL list:

   http://www.mulberrytech.com/xsl/xsl-list/index.html

It's the best resource around for XSLT questions, but I'll try to give a
brief answer to your question.

The first problem is that the DTD and stylesheet excerpts you've posted are
incorrect.  In the future, please make sure what you post is correct XML
and XSLT.  That way, we don't have to guess what your source files look
like.

So, here's what I did to create a source file to test your example:

   <?xml version="1.0"?>
   <!DOCTYPE MAIN [
       <!ELEMENT MAIN (#PCDATA | SUB)*>
       <!ELEMENT SUB (#PCDATA) >
   ]>
   <MAIN>
       Text 1 here
       <SUB>embedded text</SUB>
       Text 2 here
   </MAIN>

Note that in your post, you terminated the ELEMENT decl incorrectly with
"/>" instead of just ">".  Also, I had to guess at what the content model
really was, so I used ((#PCDATA | SUB), instead of (#PCDATA,SUB).

Next, I created the following stylesheet:

   <?xml version="1.0"?>
   <xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
     version="1.0">

   <xsl:template match="MAIN">
       <xsl:apply-templates select="."/>
       <xsl:apply-templates select="SUB"/>
   </xsl:template>

   <xsl:template match="PROCESS">
       <xsl:value-of select="."/>
   </xsl:template>

   </xsl:stylesheet>

Note that I had to remove the name attribute from the xsl:apply-templates
instructions, since there's no name attribute for that instruction.  Xalan
does report this as an error, so I can only assume you don't really have
these name attributes in your stylesheet.

So, when I ran this stylesheet, it did indeed crash the process.  That's
because the first xsl:apply-templates instruction creates an infinite loop
by selecting the current node again, and applying the same template, which
again selects the current node, etc.  The processor crashes with a stack
overflow when it finally runs out of stack space.  We do have an
enhancement request to detect this sort of thing, but it has not yet been
implemented.

At any rate, what I suspect you want is something like this:

   <?xml version="1.0"?>
   <xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
     version="1.0">

   <xsl:template match="/">
     <doc>
       <xsl:apply-templates/>
     </doc>
   </xsl:template>

   <xsl:template match="MAIN">
       <xsl:copy-of select="node()"/>
   </xsl:template>

   </xsl:stylesheet>

which produces the following result:

   <?xml version="1.0" encoding="UTF-8"?>
   <doc>
       Text 1 here
       <SUB>embedded text</SUB>
       Text 2 here
   </doc>

Since xsl:value-of creates a text node in the result tree, you cannot use
it if you want to preserve elements along with their text node children.

Hope that helps...

Dave



                                                                                
                                               
                      "Jerome                                                   
                                               
                      Delamarche"              To:      
<[email protected]>                                         
                      <[EMAIL PROTECTED]         cc:      (bcc: David N 
Bertoni/Cambridge/IBM)                                   
                      com>                     Subject: How to order content ?  
                                               
                                                                                
                                               
                      01/14/2003 10:43                                          
                                               
                      AM                                                        
                                               
                                                                                
                                               



Hi,

I must process a DTD I did not write, where tags can include PCDATA and
other embedded tags.

For example:

<!ELEMENT MAIN (#PCDATA,SUB)* />
<!ELEMENT SUB (#PCDATA) />

Then  a document may look like:

<MAIN>
    Text 1 here
    <SUB>embedded text</SUB>
    Text 2 here
</MAIN>

My problem is to output the whole text in the right order !

What "select" expression could I use to get the following result ?

Text 1 here
<b>embedded text</b>
Text 2 here

First try:

<xsl:template match="MAIN">
    <xsl:apply-templates name="PROCESS" select="."/>
    <xsl:apply-templates name="PROCESS" select="SUB"/>
</xsl:template>

<xsl:template match="PROCESS">
    <xsl:value-of select="."/>
</xsl:template>

It gives (and it seems normal):

Text 1 here
Text 2 here
embedded text

(wrong reordering)

Second try:

<xsl:template match="MAIN">
    <xsl:apply-templates name="PROCESS" select=".|SUB"/>
</xsl:template>

<xsl:template match="PROCESS">
    <xsl:value-of select="."/>
</xsl:template>

Produces a "segmentation fault" of Xalan processor !

Any suggestion ?

Thanks,

Jerome







Reply via email to