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

Re: Re: Wrapping problem

Subject: Re: Re: Wrapping problem
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Tue, 15 Aug 2006 14:00:57 +0530
wrapping characters
Hi Kent,
  Following is a XSLT 1.0 solution to the problem:

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

<xsl:output method="xml" indent="yes" />

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

<xsl:template match="scene">
 <scene name="{.}">
   <xsl:apply-templates select="following-sibling::character">
     <xsl:with-param name="gen-id" select="generate-id()" />
   </xsl:apply-templates>
 </scene>
</xsl:template>

<xsl:template match="character">
 <xsl:param name="gen-id" />

 <xsl:if test="$gen-id = generate-id(preceding-sibling::scene[1])">
   <character name="{.}">
     <xsl:apply-templates select="following-sibling::line">
       <xsl:with-param name="gen-id" select="generate-id()" />
     </xsl:apply-templates>
   </character>
 </xsl:if>
</xsl:template>

<xsl:template match="line">
 <xsl:param name="gen-id" />

 <xsl:if test="$gen-id = generate-id(preceding-sibling::character[1])">
   <xsl:copy-of select="." />
 </xsl:if>
</xsl:template>

</xsl:stylesheet>

This stylesheet, when applied to XML:

<play>
 <scene>Scene 1</scene>
 <character>char 1</character>
 <line>blah blah blah</line>
 <line>blah blah blah</line>
 <line>blah blah blah</line>
 <character>char 2</character>
 <line>blah blah blah</line>
 <line>blah blah blah</line>
 <line>blah blah blah</line>
 <character>char 3</character>
 <line>blah blah blah</line>
 <line>blah blah blah</line>
 <line>blah blah blah</line>
 <scene>Scene 2</scene>
 <character>char 1</character>
 <line>blah blah blah</line>
 <line>blah blah blah</line>
 <line>blah blah blah</line>
</play>

Produces output:

<?xml version="1.0" encoding="UTF-8"?>
<play>
  <scene name="Scene 1">
     <character name="char 1">
        <line>blah blah blah</line>
        <line>blah blah blah</line>
        <line>blah blah blah</line>
     </character>
     <character name="char 2">
        <line>blah blah blah</line>
        <line>blah blah blah</line>
        <line>blah blah blah</line>
     </character>
     <character name="char 3">
        <line>blah blah blah</line>
        <line>blah blah blah</line>
        <line>blah blah blah</line>
     </character>
  </scene>
  <scene name="Scene 2">
     <character name="char 1">
        <line>blah blah blah</line>
        <line>blah blah blah</line>
        <line>blah blah blah</line>
     </character>
  </scene>
</play>


On 8/14/06, Kent Seegmiller <hookjaw20@xxxxxxxxxxx> wrote:
My apologies. for not making that clear.  The following is my input. I want
to wrap a script from a play in a file "movie1.xml":
>> <play>
>>    <scene>Scene 1</scene>
>>       <character>char 1</character>
>>          <line>blah blah blah</line>
>>          <line>blah blah blah</line>
>>          <line>blah blah blah</line>
>>       <character>char 2</character>
>>          <line>blah blah blah</line>
>>          <line>blah blah blah</line>
>>          <line>blah blah blah</line>
>>       <character>char 3</character>
>>          <line>blah blah blah</line>
>>          <line>blah blah blah</line>
>>          <line>blah blah blah</line>
>>    <scene>Scene 2</scene>...
>>       <character>char 1</character>
>>          <line>blah blah blah</line>
>>          <line>blah blah blah</line>
>>          <line>blah blah blah</line>
>> ...
>> </play>
 The output I want to look like so:
<play>
   <scene name="Scene 1">
      <character name="char 1">
         <line>blah blah blah</line>
         <line>blah blah blah</line>
         <line>blah blah blah</line>
      </character>
      <character name="char 2">
         <line>blah blah blah</line>
         <line>blah blah blah</line>
         <line>blah blah blah</line>
      </character>
      <character name="char 3">
         <line>blah blah blah</line>
         <line>blah blah blah</line>
         <line>blah blah blah</line>
      </character>
   </scene>
   <scene name="Scene 2">
      <character> name="char 1"
         <line>blah blah blah</line>
         <line>blah blah blah</line>
         <line>blah blah blah</line>
      </character>
 ...</scene>
</play>

>> My question: How do I wrap the scenes and characters.  So far
>> my strained brain can only think of creating a text file and
>> using "&lt;scene>" or "&lt;character>" to place the end
>> element then renaming the text file to xml.
>> thanks Kent

-- Regards, Mukul Gandhi

http://gandhimukul.tripod.com

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.