[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Newbie question on XSL and lists

Subject: Newbie question on XSL and lists
From: Michiel Verhoef <michielv@xxxxxxxxx>
Date: Fri, 08 Sep 2000 10:50:09 +0200
xsl apply templates match
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@xxxxxxxxx
http://www.xs4all.nl/~michielv/


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.