xsl-list
[Top] [All Lists]

Re: [xsl] Grouping multiple tags into one parent tag

2009-02-15 13:02:28
Chad Chelius wrote:
I have xml with a section structured like this:

<body>content here</body>
<body>content here</body>
<body>content here</body>

I'd like to change all of the body elements to <p> tags and group all of those original body elements (now <p> tags) into a parent element.

Write a template for the parent element of those 'body' elements. Assuming it is named 'foo'
  <xsl:template match="foo">
    <field name="body">
      <xsl:apply-templates select="body"/>
    </field>
  </xsl:template>
  <xsl:template match="body">
    <p>
      <xsl:apply-templates/>
    </p>
  </xsl:template>

If the 'foo' element has further children and you want to process them as well then you need to do that in the match="foo" template but obviously it depends on what you want to do with those elements exactly.

--

        Martin Honnen
        http://JavaScript.FAQTs.com/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--