Subject: Basic XSL techniques From: Guralnik <guralnik@xxxxxxxxxxxx> Date: Wed, 19 Jan 2000 18:36:54 +0200 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: new poster / conditionals in fo, David Carlisle | Thread | RE: Basic XSL techniques, Mike Brown |
new poster / conditionals in for-ea, Chris Reeves | Date | WHAT IS THE "::" SYNTAX USED FOR ??, Jonathan Asbell |
Month |