[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] rendering marginal XML
Subject: RE: [xsl] rendering marginal XML From: "Chris Bayes" <chris@xxxxxxxxxxx> Date: Fri, 26 Oct 2001 20:04:25 +0100 |
Jay, Well say what you want up front. Don't beat about the bush! Mike, I don't think that will work. I think there might be a way to do it with keys but using this input <?xml version="1.0" ?> <msgs> <msgSent> <time>time sent</time> <origin>me@xxxxxxxx</origin> <r>you1@xxxxxxxxx</r> <recieved>1time recieved</recieved> <status>Any error messages, etc</status> <r>you2@xxxxxxxxx</r> <recieved>2time recieved</recieved> <r>you3@xxxxxxxxx</r> <recieved>3time recieved</recieved> <r>you4@xxxxxxxxx</r> <recieved>4time recieved</recieved> <status>Any error messages, etc</status> <r>you5@xxxxxxxxx</r> <recieved>5time recieved</recieved> </msgSent> </msgs> And this stylesheet <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/msgs"> <html> <head></head> <body> <xsl:apply-templates select="msgSent" /> </body> </html> </xsl:template> <xsl:template match="msgSent"> ERROR: <br /> <xsl:apply-templates select="status" /> SUCCESS: <br /> <xsl:apply-templates select="r" /> </xsl:template> <xsl:template match="status"> <xsl:value-of select="preceding-sibling::r[1]" /> ERROR: <xsl:value-of select="." /> AT: <xsl:value-of select="preceding-sibling::recieved[1]" /><br /> </xsl:template> <xsl:template match="r"> <xsl:variable name="ps"><xsl:call-template name="fs" /></xsl:variable> <xsl:variable name="pr"><xsl:call-template name="fr" /></xsl:variable> <xsl:if test="$pr < $ps or $pr = ''"> <xsl:value-of select="." /> SUCCESS AT: <xsl:value-of select="following-sibling::recieved" /><br /> </xsl:if> </xsl:template> <xsl:template name="fr"> <xsl:for-each select="following-sibling::r[1]"> <xsl:value-of select="count(preceding-sibling::*)" /> </xsl:for-each> </xsl:template> <xsl:template name="fs"> <xsl:for-each select="following-sibling::status[1]"> <xsl:value-of select="count(preceding-sibling::*)" /> </xsl:for-each> </xsl:template> </xsl:stylesheet> You get this output <body> ERROR: <br> you1@xxxxxxxxx ERROR: Any error messages, etc AT: 1time recieved<br> you4@xxxxxxxxx ERROR: Any error messages, etc AT: 4time recieved<br> SUCCESS: <br> you2@xxxxxxxxx SUCCESS AT: 2time recieved<br> you3@xxxxxxxxx SUCCESS AT: 3time recieved<br> you5@xxxxxxxxx SUCCESS AT: 5time recieved<br> </body> Ciao Chris XML/XSL Portal http://www.bayes.co.uk/xml > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > Michael Kay > Sent: 26 October 2001 19:02 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: [xsl] rendering marginal XML > > > > > > <msgSent> > > <time>time sent</time> > > <origin>me@xxxxxxxx</origin> > > <r>you@xxxxxxxxx</r> > > <recieved>time recieved</recieved> > > <status>Any error messages, etc</status> > > <r>you2@xxxxxxxxx</r> > > <recieved>time recieved</recieved> > > <status>Any error messages, etc</status> > > (this repeats for each recipient) > > </msgSent> > > (this repeats for each message) > > > > The problem is the <recieved> and <status> tags refer to the > > imediately preceding <r> tag. > > If the structure is sufficiently regular you can add the > necessary <recipient> element by doing > > <xsl:template match="r"> > <recipient> > <name><xsl:value-of select="."/></name> > <received><xsl:value-of > select="following-sibling::recieved[1]"/></received> > <status><xsl:value-of > select="following-sibling::status[1]"/></status> > </recipient> > </xsl:template> > > <xsl:template match="recieved|status"/> > > Mike Kay > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] rendering marginal XML, Michael Kay | Thread | RE: [xsl] rendering marginal XML, McNally, David |
RE: [xsl] rendering marginal XML, Michael Kay | Date | Re: [xsl] How to read the encoding , James Garriss |
Month |
Keywords