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

newbie problem

Subject: newbie problem
From: Laing <laing.duncan@xxxxxxxxx>
Date: Tue, 20 Sep 2005 14:43:50 +0200
measure template
Hi
I am very new to xslt and I have tried to find the aswer to my problem
in the FAQs and archives but I suppose I don't really know what i'm
looking for!

An example xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MEASURE>
<MEASURE TITLE="Test measure elements">
	<BOOLEAN NAME="boolelement" CAPTION="Is it?" CHECKED="yes" />
	<CHOICE NAME="choiceelement" CAPTION="Which one?" >
	       <CHOICE_ELEMENT VALUE="0" CAPTION="This one" CHECKED="yes" />
	        <CHOICE_ELEMENT VALUE="1" CAPTION="That one" CHECKED="no" />
	</CHOICE>
	<CHOICE NAME="choiceelementwithotheroption" CAPTION="Which one?">
	        <CHOICE_ELEMENT VALUE="0" CAPTION="This one" />
	        <CHOICE_ELEMENT VALUE="1" CAPTION="That one" />
	        <OTHER_FIELD VALUE="-1" CAPTION="Other, please specify" />
	</CHOICE>
	<MULTI_CHOICE NAME="choicemultielement" CAPTION="Which ones this
time? You can select more than one!">
	       <MULTI_CHOICE_ELEMENT VALUE="0" CAPTION="This one" CHECKED="yes" />
	       <MULTI_CHOICE_ELEMENT VALUE="1" CAPTION="That one" CHECKED="yes" />
	       <MULTI_CHOICE_ELEMENT VALUE="2" CAPTION="Another one" CHECKED="yes"
/>
	      <MULTI_CHOICE_ELEMENT VALUE="3" CAPTION="Yet another one as
well" CHECKED="no" />
	      <OTHER_FIELD VALUE="" CAPTION="Other, please specify" CHECKED="yes" />
	      <OTHER_FIELD VALUE="" CAPTION="Other, please specify" CHECKED="no" />
	</MULTI_CHOICE>
	<BOOLEAN NAME="boolelement2" CAPTION="Will it also?" CHECKED="yes" />
	<TEXT NAME="textelement" CAPTION="Enter some text:" />
	<TEXT NAME="numberelement" CAPTION="Enter a number:" NUMERICAL="yes" />
</MEASURE>

I basically want to output each element (BOOLEAN, CHOICE,
MULTI_CHOICE, TEXT...) to HTML which will differ according to what
type of element each is. The order in which they appear in the
document  should be maintained. My examples are merely printing out
the element names just now until I get the basic processing worked
out.

Now, I have tried this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">

       <xsl:output method="html"/>
       <xsl:template match="/">
        <html>
            <body>
                 <xsl:apply-templates select="MEASURE"/>
            </body>
            </html>
            </xsl:template>

              <xsl:template match="BOOLEAN">
                  <xsl:value-of select="@NAME"/><br></br>
              </xsl:template>

              <xsl:template match="CHOICE">
                  <xsl:value-of select="@NAME"/><br></br>
              </xsl:template>

              <xsl:template match="MULTI_CHOICE">
                  <xsl:value-of select="@NAME"/><br></br>
              </xsl:template>

              <xsl:template match="TEXT">
                  <xsl:value-of select="@NAME"/><br></br>
              </xsl:template>

My first MEASURE template:
<xsl:template match="MEASURE">
    <xsl:for-each select=".">
         <xsl:choose>
                   <xsl:when test="BOOLEAN">
                            <xsl:apply-templates select="BOOLEAN"/>
                    </xsl:when>
                     <xsl:when test="CHOICE">
                            <xsl:apply-templates select="CHOICE"/>
                      </xsl:when>
                      <xsl:when test="MULTI_CHOICE">
                            <xsl:apply-templates select="MULTI_CHOICE"/>
                      </xsl:when>
                      <xsl:when test="TEXT">
                            <xsl:apply-templates select="TEXT"/>
                      </xsl:when>
           </xsl:choose>
   </xsl:for-each>
</xsl:template>

Produced this HTML. Now it would appear that not all nodes have been
processed. Only those matching BOOLEAN, one of which was the first,
have been processed?
<html>
<head>
<body>
h2>boolelement<br>boolelement2<br>
</body>
</html>

My next attempt:
<xsl:template match="MEASURE">
          <xsl:for-each select=".">
                  <xsl:if test="BOOLEAN">
                       <xsl:apply-templates select="BOOLEAN"/>
                  </xsl:if>
                  <xsl:if test="CHOICE">
                       <xsl:apply-templates select="CHOICE"/>
                   </xsl:if>
                    <xsl:if test="MULTI_CHOICE">
                       <xsl:apply-templates select="MULTI_CHOICE"/>
                    </xsl:if>
                    <xsl:if test="TEXT">
                       <xsl:apply-templates select="TEXT"/>
                    </xsl:if>
      </xsl:for-each>
</xsl:template>

was more successful:
<html>
<body>
<h2 align="center">Test all the available measure
elements</h2>boolelement<br>boolelement2<br>choiceelement<br>choiceelementwit
hotheroption<br>choicemultielement<br>textelement<br>numberelement<br>
</body>
</html>

 However the order is wrong. I have looked at the info regarding
sorting but can't quite grasp what I need to do. Also, why does the
first attempt fail so miserably, there's obviously something I'm not
quite grasping about conditional processing?

I know I have a lot to learn!

thanks and kind regards

Laing

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.