Subject: RE: Copying and transforming/Recursion? From: Jeff Saylor <JSaylor@xxxxxxxxxxxxxxxxx> Date: Wed, 11 Oct 2000 14:43:51 -0400 |
John, Thanks for the input but - like Sara's solution - this requires that I know the structure inside of <display> ahead of time - I need something more dynamic, hence why I was thinking about recursion to move through the children since it could handle a different structure every time. Ideas? Cheers, Jeff -----Original Message----- From: John E. Simpson [mailto:simpson@xxxxxxxxxxx] Sent: Tuesday, October 10, 2000 4:46 PM To: xsl-list@xxxxxxxxxxxxxxxx Subject: Re: Copying and transforming/Recursion? At 02:45 PM 10/10/2000 -0400, Jeff Saylor wrote: >Starting with: > > <xml> > <submittedValues> > <submittedValue fieldname='title'>mr.</submittedValue> > </submittedValues> > > <display> > <p> > title:<input type='text' fieldname='title' value=''/> > </p> > </display> > </xml> > >Effectively, I want to use the <submittedValue>'s text with the matching (by >@fieldname) <display>'s <input> to get: > > <display> > <p> > title:<input type='text' fieldname='title' value='mr.' /> > </p> > </display> Well, it's hard to generalize from a small XML doc. But if all your submittedValues and display elements follow this regular pattern, this should work: <xsl:template match="xml_root"> <xsl:for-each select="submittedValues/submittedValue"> <xsl:if test="./@fieldname=../following-sibling::*//input/@fieldname"> <display> <p>title: <input type="text" fieldname="{@fieldname}"> <xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute> </input> </p> </display> </xsl:if> </xsl:for-each> </xsl:template> (Btw, I changed the name of your root "xml" element to "xml_root." I didn't know if you really meant for an element to be called "xml" but if so, it offended what few purist sensibilities I still have. :) Looks okay in IE5 (Sept. '00 release), and Saxon outputs: <display> <p>title: <input type="text" fieldname="title" value="mr."> </p> </display> >this involves outputting the <display> tag, and its contents, while >selectively transforming an element within them - I can not figure out a way >to do this. I am thinking copy-of and recursive templates would do the >trick, but I can't get a grasp on how to do it... Sorry, I didn't use copy-of or recursive templates! =============================================================== John E. Simpson | "He asked me if I knew what http://www.flixml.org | time it was. I said, 'Yes, but XML Q&A: http://www.xml.com | not right now.'" (Steven Wright) XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: Copying and transforming/Recurs, Jeff Saylor | Thread | RE: Copying and transforming/Recurs, John E. Simpson |
RE: Insert an attribute to all node, Ron Ten-Hove | Date | Documenting stylesheets, Meltsner, Kenneth |
Month |