[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Re: Wrapping problem
This solution is likely to be O[n^2] with respect to the number of lines in the play, which could be rather large. A recursive traversal that uses apply-templates select="following-sibling::*[1]" would be O[n]. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Mukul Gandhi [mailto:gandhi.mukul@xxxxxxxxx] > Sent: 15 August 2006 09:31 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: Re: Wrapping problem > > 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 > > >> "<scene>" or "<character>" to place the end element then > > >> renaming the text file to xml. > > >> thanks Kent > > -- > Regards, > Mukul Gandhi > > http://gandhimukul.tripod.com
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|