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: Newbie question on XSL and lists


Michiel,
Try

<xsl:template match="par-f">
	<xsl:apply-templates />
</xsl:template>
<xsl:template match="listing">
	<xsl:if test="./item">
		<xsl:apply-templates select="item" />
	</xsl:if>
	<xsl:if test="not() ./item">
		<xsl:message terminate="yes">ooops</xsl:message>
	</xsl:if>
</xsl:template>
<xsl:template match="item">
	<xsl:if test="./par-f">
		*<xsl:apply-templates select="par-f"/>
	</xsl:if>
	<xsl:if test="not() ./par-f">
		<xsl:message terminate="yes">ooops</xsl:message>
	</xsl:if>
</xsl:template>

or something a bit like it. 
Beginner rule #1 *NEVER* use xsl:for-each

Ciao Chris

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


>-----Original Message-----
>From: owner-xsl-list@mulberrytech.com
>[mailto:owner-xsl-list@mulberrytech.com]On Behalf Of Michiel Verhoef
>Sent: 08 September 2000 09:50
>To: xsl-list@mulberrytech.com
>Subject: Newbie question on XSL and lists
>
>
>Hi all,
>
>Though I have been reading the XSL list for a while I only recently 
>made my first steps in writing my own XSL style sheets.
>
>Does anybody know of a good tutorial on XSL? I'm sort of experienced
>in writing CSS and (think I) have a decent knowledge of the general
>ideas of stylesheets but I need a manual. Any good book recommendations
>are also welcome.
>
>I ran into a problem which I think has something to do with the structure
>the document I'm trying to display has.
>
>
>In a nutshell the problem structure is this:
>
><par-f>
>  <listing>
>     <item>
>        <par-f>
>     </item>
>     <item>
>        <par-f>
>     </item>
>  </listing>
></par-f>
>
>I am trying to get a listing on my screen (like HTML's <ul>) but only get
>either no
>content of the <par-f> or the content of the <par-f> within <item> twice.
>
>The algoritm should be something like:
>If <par-f> contains a <listing>
>    process the <listing>
>else
>   display the content of <par-f>
>endif
>
>if the <listing> contains <item>
>   process the <item>
>else
>  /* error */
>endif
>
>if the <item> contains a <par-f>
>   process the <par-f>
>else
>  /* error */
>endif
>
>Assuming this idea is reasonably close to reality I haven't got a clue how
>to get
>this done in XSL. Any hints and tips would be very welcome.
>
>Thanks in advance,
>
>Michiel
>
>
>
>Basically my output looks like this:
>
>The data types can be divided into five categories:
>category1;category2;category3;category4;category5. * 
>* 
>* 
>* 
>* 
>category1;category2;category3;category4;category5.
>
>Whereas is should look like:
>
>The data types can be divided into five categories: 
>* category1;
>* category2;
>* category3;
>* category4;
>* category5.
>
>
>My style sheet looks like this:
><?xml version="1.0" ?>
>
><xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" >
><xsl:template><xsl:apply-templates/></xsl:template>
>
><html>
><head>
><title>Section1</title>
></head>
><body>
><xsl:apply-templates/>
></body>
></html>
>
><xsl:template match="section1">
>	<h2><xsl:value-of select="stitle"/></h2><hr/>
>	<xsl:apply-templates match="introduction"/>
>	<hr/>
></xsl:template>
>
>
><xsl:template match="introduction">
><!--        <xsl:value-of select="par-f"/>
>	<xsl:for-each select="listing">
>		<xsl:apply-templates match="listing"/>
>	</xsl:for-each>-->
>	<xsl:apply-templates/>
>	<xsl:for-each select="par-f">
>		<xsl:apply-templates match="par-f"/>
>	</xsl:for-each>
>
></xsl:template>
>
><xsl:template match="functional-description">
>	<xsl:apply-templates/>
></xsl:template>
>
><xsl:template match="subsection">
>	<h3><xsl:value-of select="stitle"/></h3><hr/>
>	<xsl:apply-templates/>
>        <xsl:for-each select="/par-f">
>	   <xsl:apply-templates match="par-f"/><br/>
>	</xsl:for-each>
></xsl:template>
>
>
><xsl:template match="listing">
>	<xsl:for-each select="item">
>        	<xsl:apply-templates match="item"/>
>	</xsl:for-each>
></xsl:template>
>
><xsl:template match="item">
>	* <xsl:value-of select="/par-f"/> <br/>
></xsl:template>
>
><xsl:template match="par-f">
>        <xsl:value-of/>
>	<xsl:for-each select="listing">
>		<xsl:apply-templates match="listing"/>
>	</xsl:for-each>
></xsl:template>
>
>
></xsl:stylesheet>
>
>
>My content looks like this:
>
><?xml version="1.0"?>
><?xml-stylesheet href="kapdoc.xsl" type="text/xsl"?>
><!DOCTYPE section1 SYSTEM "kapdoc.dtd">
><section1><stitle>Data Model</stitle>
><docsection><stitle><?xm-replace_text {stitle}?></stitle>
><introduction><par-f>The data types can be divided into five categories: 
><listing type="ord">
>   <item><par-f>category1;</par-f></item>
>   <item><par-f>category2;</par-f></item>
>   <item><par-f>category3;</par-f></item>
>   <item><par-f>category4;</par-f></item>
>   <item><par-f>category5.</par-f></item>
>   </listing> </par-f></introduction>
></docsection></section1>
>
>The relevant parts of the DTD are:
>
><!ELEMENT par-f  (#PCDATA|listing)*>
><!ELEMENT listing  (stitle? , item+ )>
><!ELEMENT item  (par-f | listing )+>
>
>
>--
>"If at first you don't succeed, destroy all evidence that you ever tried"
>
>Michiel Verhoef
>
>michielv@xs4all.nl
>http://www.xs4all.nl/~michielv/
>
>
> 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]