[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Closing and opeing tag in that order

Subject: RE: Closing and opeing tag in that order
From: Mike Ferrando <mikeferrando@xxxxxxxxx>
Date: Fri, 27 Dec 2002 05:00:12 -0800 (PST)
xsl test gt
Chandra,
Here is how I did it. I think that you could save yourself alot of
trouble by making the loose text attributes of tag1. (below)

I didn't put data3 loose in tag1, I thought this inconsistency must
be an oversight of somekind.

Sincerely,
Mike Ferrando
Washington, DC

===output:===
<?xml version="1.0" encoding="utf-8" standalone="no"?>

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


===XML:===
<?xml version="1.0" encoding="utf-8" standalone="no"?>

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


===XSL:===
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet   version="1.0"  
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output version="1.0" method="xml" indent="yes" encoding="utf-8"
omit-xml-declaration="no" standalone="no" media-type="text/xml"/>

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

<xsl:template match="tag1">
  <xsl:apply-templates mode="xxx"/>
</xsl:template>

<xsl:template match="tag2" mode="xxx">
  <tag1>
   <tag2>
    <xsl:apply-templates/>
   </tag2>
  </tag1>
</xsl:template>

<xsl:template match="text()" mode="xxx">
 <xsl:variable name="test" select="normalize-space(.)"/>
  <xsl:choose>
   <xsl:when test="string-length($test)&gt;1">
    <tag1>
     <xsl:value-of select="normalize-space(translate(., '&#xA;',
''))"/>
    </tag1>
   </xsl:when>
   <xsl:otherwise>
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="text()">
<xsl:value-of select="normalize-space(translate(., '&#xA;', ''))"/>
</xsl:template>

</xsl:stylesheet>

--- Chandra - <pchandramohan@xxxxxxxxxxx> wrote:
> Hi Tom,
>   Thanks for the quick reply. Well for the tag structure you
> mentioned
> ------
> >>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>
> -----
> the output should be
> 
> 
> <tag1>
>     data1
> </tag1><tag1>
>     <tag2>data2</tag2>
>     data3
> </tag1><tag1>
>     <tag2>data4</tag2>
> </tag1><tag1>
>     <tag2>data5</tag2>
>   </tag1>
> 
> You see the dtd states that "a <tag1> element can have a  SINGLE
> <tag2> 
> element as child provided <tag1> is IMMEDIATELY followed by <tag2>.
> 
>   The document is a valid  and well formed finally even though i
> add the 
> tags in this manner </tag1><tag1>.
>   Regrouping the elements is not feasible in my situation as
> several other 
> things would be affected. I was hence wondering whether there was
> any 
> solution. If I use <xml:output> tag to show as "text". would that
> work??
> Thanks in advance
> Regards,
> Chandra
> 
> 
> 
> 
> 
> 
> 
> 
> ----Original Message Follows----
> From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Subject: RE:  Closing and opeing tag in that order
> 
> [ 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
> 
> 
> _________________________________________________________________
> The new MSN 8: smart spam protection and 3 months FREE*. 
>
http://join.msn.com/?page=features/junkmail&xAPID=42&PS=47575&PI=7324&DI=7474&SU=
> 
>
http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_smartspamprotection_3mf
> 
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.