This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Checking value of a previous text node


Hello Ryan,

your problem is a really simlpe grouping problem. Have a look at http://www.dpawson.co.uk/xsl/sect2/N4486.html or at more special techniques like Muenchian Grouping at http://www.jenitennison.com/xslt/grouping/muenchian.xml.

The code for Muenchian Grouping:

<xsl:key name="classes" match="class" use="quarterName"/>

<xsl:template match="enrolledClasses">
<xsl:apply-templates select="classes[generate-id() = generate-id(key('classes', quarterName))]" mode="group"/>
</xsl:template>

<xsl:template match="classes" mode="group">
<i><xsl:value-of select="quarterName"/></i><br/>
<p>
<xsl:apply-templates select="key('classes', quarterName)"/>
</p>
</xsl:template>

<xsl:template match="classes" mode="all">
<xsl:value-of select="name"/><br/>
</xsl:template>

(untested)

Regards,

Joerg


Ryan O'Leary wrote:

Hi all. I've been having a lot of trouble trying to get this to work,
although I'm sure theres a simple answer. I have the following XML:

=== START XML ===

<?xml version="1.0" encoding="UTF-8"?>
<root>
<enrolledClasses>
<class>
<name>Behavior Disorders</name>
<quarterName>Fall 2001</quarterName>
</class>
<class>
<name>ADDITIONAL ENGR LAB</name>
<quarterName>Summer 2002</quarterName>
</class>
<class>
<name>SENIOR PROJECT</name>
<quarterName>Summer 2002</quarterName>
</class>
<class>
<name>C and UNIX</name>
<quarterName>Spring 2002</quarterName>
</class>
</enrolledClasses>
</root>

===== END XML ======

And I would like to produce the following HTML:

===== START HTML =====

<i>Fall 2001</i><br />
Behavior Disorders <br />
<p>
<i>Summer 2002</i><br />
ADDITIONAL ENGR LAB<br />
SENIOR PROJECT<br />
<p>
<i>Spring 2002</i><br />
C and UNIX<br />
<p>

===== END HTML =====

I am having problems writing XSL that will recognize when the
quarterName value has changed and display the quarter only then. I've
tried all kinds of stuff, but I haven't gotten it to work. As a side
note, I can't rewrite the XML to group the classes by quarter because of
the way the XML gets populated.
If anyone could help me with some code that checks the current value of
quarterName against the last value to see if its changed, that would be
awesome!!

Thanks in advance.

- Ryan O'Leary
- ryan-portal@polyinteractive.com

XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]