[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: Copying and transforming/Recursion?


Subject: Re: Copying and transforming/Recursion?
From: "John E. Simpson" <simpson@xxxxxxxxxxx>
Date: Tue, 10 Oct 2000 16:45:41 -0400

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




Current Thread
Keywords
xml