Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2004, 10:18 AM
Registered User
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default putting <element> round group of same elements

As u can see in my code below i'm still an xslt newbie but i'm learning (slowly).

I have one problem I can't seem to solve : after processing i'll have a structure
<records>
<record>
<element1>...</element1>
<element2>...</element2>
....
<element9>...</element9>
<element9>...</element9>
</record>
</record>
<element1>...</element1>
<element2>...</element2>
...
<element9>...</element9>
<element9>...</element9>
<element9>...</element9>
</record>

I would like to group the <element9> elements in a <question> element
<records>
<record>
<element1>...</element1>
<element2>...</element2>
....
<question>
<element9>...</element9>
<element9>...</element9>
</question>
</record>
</record>
<element1>...</element1>
<element2>...</element2>
...
<question>
<element9>...</element9>
<element9>...</element9>
<element9>...</element9>
</question>
</record>

this is my code so far ...

<?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" version="1.0" encoding="UTF-8" indent="yes"/>


<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="part">
<records>
<xsl:apply-templates select="node()"/>
</records>
</xsl:template>

<xsl:template match="inline">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="document">
<xsl:apply-templates select="node()"/>
</xsl:template>

<xsl:template match="documentinfo">
<xsl:apply-templates select="node()"/>
</xsl:template>

<xsl:template match="property">
<xsl:apply-templates select="node()"/>
</xsl:template>


<xsl:template match="par[normalize-space(.) = 'start']">

<record>
<xsl:element name="element1">
<xsl:apply-templates select="node()"/>
</xsl:element>

<xsl:apply-templates select="following-sibling::par[1]" mode="renumber">
<xsl:with-param name="counter" select="2"/>
</xsl:apply-templates>
</record>
</xsl:template>



<xsl:template match="par">
</xsl:template>


<xsl:template match="par" mode="renumber">
<xsl:param name="counter"/>

<xsl:if test="normalize-space(.) != 'start'">

<xsl:element name="element{$counter}">
<xsl:apply-templates select="node()"/>
</xsl:element>
<xsl:if test="$counter < 9" >

<xsl:apply-templates select="following-sibling::par[1]" mode="renumber">
<xsl:with-param name="counter" select="1 + $counter"/>
</xsl:apply-templates>
</xsl:if>
<xsl:if test="$counter >= 9" >

<xsl:apply-templates select="following-sibling::par[1]" mode="renumber">
<xsl:with-param name="counter" select="9"/>
</xsl:apply-templates>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>


if the easiest solution is another xslt processing, i'm ready to do so, as i'm running out of ideas.
thanx in advance






Similar Threads
Thread Thread Starter Forum Replies Last Post
embedded <xsl:element> into <xsl:with-param> petergoodman XSLT 2 July 9th, 2008 06:36 AM
Putting and input in <STDIN> ZORCH Perl 1 June 14th, 2007 09:58 AM
create <ul> with alternating class on <li> element Brian Campbell XSLT 2 November 3rd, 2006 06:07 PM
how to add all <price> element value? hbcontract XML 4 November 14th, 2003 05:52 PM
putting xml data in a html <table> rev XSLT 4 September 10th, 2003 08:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.