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

RE: Which commands to use: xsl:if, xsl:when, xsl:choo

Subject: RE: Which commands to use: xsl:if, xsl:when, xsl:choose, xsl:otherwise ??
From: "Kenny Akridge" <kakridge@xxxxxxxxxxxxx>
Date: Tue, 27 Jan 2004 14:20:35 -0500
if xsl
Bill,

This template will work with both of your html needs:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="page/links">
	<xsl:apply-templates/>
	

</xsl:template>

<xsl:template match="categories">
<xsl:if test="normalize-space(.)">
	Categories: <br/>
	<xsl:apply-templates/>
</xsl:if>
</xsl:template>


<xsl:template match="category">
	<xsl:value-of select="."/><br/>
	
</xsl:template>

<xsl:template match="database-links">
<xsl:if test="normalize-space(.)">	
	<p/>Database Links: <br/>
	<xsl:apply-templates/>
</xsl:if>
</xsl:template>


<xsl:template match="database-link">
	<xsl:value-of select="."/><br/>

</xsl:template>

<xsl:template match="website-links">
<xsl:if test="normalize-space(*/@filename)">	
	<p/>Website Links: <br/>
	<xsl:apply-templates/>
</xsl:if>
</xsl:template>


<xsl:template match="website-link">
	<xsl:value-of select="@filename"/><br/>

</xsl:template>

</xsl:stylesheet>

It is in rough form, but you really don't need any logic.  You should
get the gist of what is going on here though.

Let me know if you have any questions.

Kenny Akridge

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Bill Walker
Sent: Tuesday, January 27, 2004 1:31 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Which commands to use: xsl:if, xsl:when, xsl:choose,
xsl:otherwise ??

Hi

I have learned just enough XML and XSLT to think I
understand what I am doing. 

However, when I am faced with something that takes
more logic and real understanding of such things as:

xsl:if

xsl:choose

xsl:when

xsl:otherwise 

.I find I really don't understand how to use them or
what is going on with the XSLT and the processing.

Here is my problem.

I am a librarian and am working on redesigning our
Library's website. Our plan is to group a lot of
information into 30 Subject Categories on the right
side of our opening screen.

http://www.stockton.lib.ca.us/new_webroot/index.htm

So far so good.

Underlying this idea, our committee decided to make
every single link on each subject and sub-category
page a separate XML file.  For example, they all start
as Dublin Core and look like this:

http://www.stockton.lib.ca.us/xml_xsl_html_samples/bureau-labor-stats.xm
l

Little by little we are beginning to do this. So each
Subject Opening page will look like this example:

http://www.stockton.lib.ca.us/new_webroot/statistics/stat-openpg.htm

This page was generated from:

http://www.stockton.lib.ca.us/xml_xsl_html_samples/stat-openpg.xsl

http://www.stockton.lib.ca.us/xml_xsl_html_samples/stat-openpg.xml

For any page one level in we have a more simple page
that looks like this:

http://www.stockton.lib.ca.us/new_webroot/statistics/stat-gensit.htm

This is generated from a different XSL file and XML
file:

http://www.stockton.lib.ca.us/xml_xsl_html_samples/stat-secondpage.xsl

http://www.stockton.lib.ca.us/xml_xsl_html_samples/stat-gensit.xml

This all works pretty well and I COULD just go on and
create an XML and an XSL file for each page.

But I began thinking, "There must be a way using
xsl:if or xsl:when or xsl:choose or xsl:otherwise to
make it so I could have ONE and one only XSL file for
the whole site.

So I simplified an XML file to include what needs to
be (or not be) on all pages which would look like
this:

<?xml version="1.0" ?> 
  <page>
      <links>
          <categories>
              <category>Metaphysics</category> 
          </categories>

          <database-links>
              <database-link>InfoTrac</database-link> 
          </database-links>

          <website-links>
               <website-link
filename="bureau-labor-stats.xml" /> 
          </website-links>
       </links>
    </page>


The idea is that no matter whether I was generating an
opening Subject screen or a page further in, all the
info. I need should be in this XML file.

What I cannot figure out is how to make XSL look at
this XML file and process it sequentially.

If it is an opening page, it will crank out the
Categories, Databases and the Weblinks lists .

If it is one page further in, it would have only
web-links.  It would look the example below and,
finding no Categories And no Databases, it would just
list the Websites...

<?xml version="1.0" ?> 
   <page>
       <links>
           <categories>
                <category /> 
           </categories>

           <database-links>
                <database-link /> 
           </database-links>

           <website-links>
               <website-link
filename="bureau-labor-stats.xml" /> 
           </website-links>
       </links>
  </page>

Can someone please help me understand how to do this.

I have tried many ways, but it is clear that I still
don't truly understand which commands are appropriate
and how to incorporate them into the XSL.

I really appreciate the expertise available on this
list and heartily thank anyone who has been kind
enough to read this far and give my little task some
consideration.

Thanking you all in advance.

--Bill Walker  
  Reference Dept.
  Stockton-San Joaquin County Public Library


 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

 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

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.