xsl-list
[Top] [All Lists]

RE: Closing and opeing tag in that order

2002-12-26 09:32:52
[ Chandra]
 I need to tansform an xml document into another xml 
document so that the 
transformed xml document conforms to a certain dtd.
  In order to do that, I need to add a closing tag followed 
by an opening 
tag. For eg:

The initial document:
<tag1>
  data1
  <tag2>data2</tag2>
</tag1>


The transformed document must be
<tag1>
  data1
</tag1><tag1>         <!--LINE 3-->
  <tag2>data2</tag2>
</tag1>

So u see, I need the LINE3 to be added. The XSLT processor 
gives me an error 
when I try to do that.

Of course it gives you an error - you are trying to use non-well-formed
xml in the stylesheet.  You do NOT need to add your LINE3.  Instead, you
need to regroup your elements.  To do that, you need to understand what
the rules for regrouping are.  You have not conveyed them clearly yet,
but once you do, either you will see what to do or the we can help you.

For example, is each instance of a tag2 element supposed to be the only
child of a tag1 element?  If you had a document like this, what should
the output look like?

<tag1>
   data1
   <tag2>data2</tag2>
   data3
   <tag2>data4</tag2>
   <tag2>data5</tag2>
 </tag1>

Or, if you cannot have a document like this, what combinations are
allowed in the source document?  Just get clear on what your
transformation really has to be, and until you do that stop thinking
like "adding a line".  XSLT is about changing one tree to another - not
about adding lines of text or markup - and that is how you need to think
about your problem.

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>