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]

RE: rendering marginal XML


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@here.com</origin>
	<r>you1@there.com</r>
	<recieved>1time recieved</recieved>
	<status>Any error messages, etc</status>
	<r>you2@there.com</r>
	<recieved>2time recieved</recieved>
	<r>you3@there.com</r>
	<recieved>3time recieved</recieved>
	<r>you4@there.com</r>
	<recieved>4time recieved</recieved>
	<status>Any error messages, etc</status>
	<r>you5@there.com</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 &lt; $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@there.com ERROR: Any error messages, etc AT: 1time recieved<br>
you4@there.com ERROR: Any error messages, etc AT: 4time recieved<br>
SUCCESS: <br>
you2@there.com SUCCESS AT: 2time recieved<br>
you3@there.com SUCCESS AT: 3time recieved<br>
you5@there.com SUCCESS AT: 5time recieved<br>
</body>

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml


> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com 
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of 
> Michael Kay
> Sent: 26 October 2001 19:02
> To: xsl-list@lists.mulberrytech.com
> Subject: RE: [xsl] rendering marginal XML
> 
> 
> >
> > <msgSent>
> > 	<time>time sent</time>
> > 	<origin>me@here.com</origin>
> > 	<r>you@there.com</r>
> > 	<recieved>time recieved</recieved>
> > 	<status>Any error messages, etc</status>
> > 	<r>you2@there.com</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


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