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

Basic XSL techniques

Subject: Basic XSL techniques
From: Guralnik <guralnik@xxxxxxxxxxxx>
Date: Wed, 19 Jan 2000 18:36:54 +0200
basic xsl
Hi XML gurus!
 
Being a novice in this field, and therefore unable to figure out what's wrong, can you help me with this:
 
1) I need to create a half-fixed half-flexible document. Now, XML is, of course, the best way to do it, but I'm having a difficulty in understanding what's the exact difference between select/match, that is, which is better to use in each case.
 
2) For example, my document begins by select-ing a specific ELEMENT from a XML file that contains multiple ELEMENT nodes. now, the next thing it has to do, is first render the document's fixed parts - title, classification, description etc. I've attached a non-working example of what I'm trying to do, which is basically all about properly matching up select and match templates. Probably a very basic error, but I'm just unable to see what's wrong in it...
 
3) Then, the next part of the document is a flexible one - that is, every ELEMENT has different content. What the XSL stylesheet must do is go over all the hierarchy, and use the appropriate template again every node, if such a template exists. The question is whether the following technique is enough for this?
 
<xsl:template match="*"><xsl:apply-templates select="@*"/></xsl:template>
 
<xsl:template match="*[node()]">
  <xsl:apply-templates select="@*"/>
  <DIV><xsl:apply-templates select="node()"/></DIV>
</xsl:template>
 
4) What is the reason for using scoped templates? that is, something like:
 
<xsl:template>
 
  <xsl:apply-templates>
 
  <xsl:template match="...">1st template</xsl:template>
  <xsl:template match="...">2nd template</xsl:template>
  <xsl:template match="...">etc. </xsl:template>
 
  </xsl:apply-templates>
</xsl:template>
 
Also, if I put an APPLY-TEMPLATES element inside a scoped template (say the 2nd template in the previous example), how far it will go up the templates hierarchy? Will it be able to use only the 1st and the 3rd "sibling" templates, or does it also apply parent templates, (siblings of the template they're scoped in, and so on.)
 
5) Somewhat related to 4, consider this:
 
<xsl:template match="...">
  ...do something...
  <xsl:apply-templates/>
</xsl:template>
 
Can this template become self-recurring, that is, be called from within itself?
 
Thanks everybody in advance - any response will be VERY appreciated,
Benjamin
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="xsl-test1.xsl"?>

<ELEMENTS>

<ELEMENT title="The 5th Element">
<DESC>Starring Bruce Willis</DESC>
</ELEMENT>

</ELEMENTS>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template select="ELEMENTS/ELEMENT[@title='%Do block']">
	<HTML><BODY>

	WHY DOESN'T THE FOLLOWING TEMPLATE-CALL WORK?
	<xsl:apply-templates select="DESC"/>

	</BODY></HTML>
</xsl:template>

<xsl:template match="*"><xsl:apply-templates select="@*"/></xsl:template>

<xsl:template match="*[node()]">
	<xsl:apply-templates select="@*"/>
	<DIV><xsl:apply-templates select="node()"/></DIV>
</xsl:template>

<xsl:template match="DESC">
	<b><xsl:value-of/></b>
</xsl:template>

<xsl:template match="text()"><xsl:value-of /></xsl:template>

</xsl:stylesheet>
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.