Subject: Re: [xsl] using position() inside Muenchian groups? From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 14 Oct 2008 08:42:19 -0400 |
I'm only at the stage of cargo culting at the moment :-( I estimate it would take about 2 hours of fumbling in the dark to figure out just the Muenchian grouping code, which could all be for naught if it turns out that position() within the for-each for the keyed group is relative to the subset and not the original set.
I want to produce output that looks like this:
> Title: The Alice > Producer: Alan Jones*, Zachary Azimuth > Director: Bill Smith > Writer: Dicky Dickens > > Title: Mini Mini > Producer: Wal Walliams* > Director: Wal Walliams* > Writer: Wal Walliams*
I'm working on it :-) Hard to write code like this though because I don't know if the wrong answers I'm getting is because I got a bug in my code, or because it is simply impossible.
T:\ftemp>type eric.xml <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult"> <RESULTSET FOUND="3"> <ROW MODID="0" RECORDID="1"> <COL><DATA>1</DATA></COL> <COL><DATA>The Alice</DATA></COL> <COL> <DATA>PRDC</DATA> <DATA>EXCP</DATA> <DATA>DRCT</DATA> <DATA>DOPH</DATA> <DATA>EXCP</DATA> <DATA>PRDC</DATA> <DATA>WRTR</DATA> </COL> <COL> <DATA>Alan Jones</DATA> <DATA>Big Cheese</DATA> <DATA>Bill Smith</DATA> <DATA>Camera Guy</DATA> <DATA>Little Cheese</DATA> <DATA>Zachary Azimuth</DATA> <DATA>Dicky Dickens</DATA> </COL> <COL> <DATA></DATA> <DATA></DATA> <DATA>Yes</DATA> <DATA></DATA> <DATA></DATA> <DATA></DATA> <DATA></DATA> </COL> </ROW> <ROW MODID="0" RECORDID="3"> <COL><DATA>3</DATA></COL> <COL><DATA>Mini Mini</DATA></COL> <COL>
<DATA>DRCT</DATA> <DATA>PRDC</DATA> <DATA>WRTR</DATA> </COL> <COL> <DATA>Wal Walliams</DATA> <DATA>Wal Walliams</DATA> <DATA>Wal Walliams</DATA> </COL> <COL> <DATA>Yes</DATA> <DATA>Yes</DATA> <DATA>Yes</DATA> </COL> </ROW> </RESULTSET> </FMPXMLRESULT>
T:\ftemp>type eric1.txt Title: The Alice Producers: Alan Jones,Zachary Azimuth Director: Bill Smith* Writer: Dicky Dickens
Title: Mini Mini Producer: Wal Walliams* Director: Wal Walliams* Writer: Wal Walliams*
T:\ftemp>type eric1.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fm="http://www.filemaker.com/fmpxmlresult" version="1.0">
<xsl:variable select="1" name="title_id" /> <xsl:variable select="2" name="title" /> <xsl:variable select="3" name="crew_role" /> <xsl:variable select="4" name="crew_name" /> <xsl:variable select="5" name="crew_flag" />
<xsl:template match="/"> <xsl:apply-templates select="*/*/fm:ROW"/> </xsl:template>
<xsl:template match="fm:ROW"> <xsl:if test="position()>1"><xsl:text>
</xsl:text></xsl:if> <xsl:text>Title: </xsl:text> <xsl:value-of select="fm:COL[$title]/fm:DATA"/> <xsl:text>
</xsl:text> <xsl:call-template name="do-role"> <xsl:with-param name="title">Producer</xsl:with-param> <xsl:with-param name="indicator">PRDC</xsl:with-param> </xsl:call-template> <xsl:call-template name="do-role"> <xsl:with-param name="title">Director</xsl:with-param> <xsl:with-param name="indicator">DRCT</xsl:with-param> </xsl:call-template> <xsl:call-template name="do-role"> <xsl:with-param name="title">Writer</xsl:with-param> <xsl:with-param name="indicator">WRTR</xsl:with-param> </xsl:call-template> </xsl:template>
T:\ftemp>type eric2.txt Title: The Alice PRDC: Alan Jones,Zachary Azimuth EXCP: Big Cheese,Little Cheese DRCT: Bill Smith* DOPH: Camera Guy WRTR: Dicky Dickens
Title: Mini Mini DRCT: Wal Walliams* PRDC: Wal Walliams* WRTR: Wal Walliams*
T:\ftemp>type eric2.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fm="http://www.filemaker.com/fmpxmlresult" version="1.0">
<xsl:variable select="1" name="title_id" /> <xsl:variable select="2" name="title" /> <xsl:variable select="3" name="crew_role" /> <xsl:variable select="4" name="crew_name" /> <xsl:variable select="5" name="crew_flag" />
<xsl:template match="/"> <xsl:apply-templates select="*/*/fm:ROW"/> </xsl:template>
<xsl:template match="fm:ROW"> <xsl:if test="position()>1"><xsl:text>
</xsl:text></xsl:if> <xsl:text>Title: </xsl:text> <xsl:value-of select="fm:COL[$title]/fm:DATA"/> <xsl:text>
</xsl:text> <xsl:variable name="production" select="."/> <xsl:variable name="role" select="fm:COL[$crew_role]/fm:DATA"/> <xsl:for-each select="$role"> <xsl:if test="generate-id(.)= generate-id($role[.=current()][1])"> <xsl:call-template name="do-role"> <xsl:with-param name="indicator" select="."/> <xsl:with-param name="production" select="$production"/> </xsl:call-template> </xsl:if> </xsl:for-each> </xsl:template>
<xsl:template name="do-role"> <xsl:param name="indicator"/> <xsl:param name="production"/> <xsl:if test="$production/fm:COL[$crew_role]/fm:DATA[.=$indicator]"> <xsl:value-of select="$indicator"/> <xsl:text>: </xsl:text> <!--find all--> <xsl:for-each select="$production/fm:COL[$crew_role]/ fm:DATA[.=$indicator]"> <xsl:if test="position()>1">,</xsl:if> <!--note index in the collection of DATA elements--> <xsl:variable name="this-role"><xsl:number/></xsl:variable> <!--use that index in other columns--> <xsl:value-of select="$production/fm:COL[$crew_name]/ fm:DATA[number($this-role)]"/> <xsl:if test="$production/fm:COL[$crew_flag]/ fm:DATA[number($this-role)]='Yes'"> <xsl:text>*</xsl:text> </xsl:if> </xsl:for-each> </xsl:if> <xsl:text>
</xsl:text> </xsl:template>
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] using position() inside M, Eric Scheid | Thread | Re: [xsl] using position() inside M, Eric Scheid |
RE: [xsl] generating ID strings tha, Michael Kay | Date | [xsl] EXSLT and XSLT 2.0, Jesper Tverskov |
Month |