[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Which commands to use: xsl:if, xsl:when, xsl:choose, xsl:otherwise ??


Subject: RE: [xsl] 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

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: [xsl] 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
Keywords