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

Re: Generating XSLT

Subject: Re: Generating XSLT
From: Geert Josten <Geert.Josten@xxxxxxxxxxx>
Date: Fri, 12 Nov 2004 21:56:02 +0100
xsl element name variable
I wouldn't have used the variable named tags, but matched for "*" with a xsl:if inside the template to pick the first of similar elements as you do with your second for-each in the variable tags. That way, you could easily add a separate match "div" with its own body.

Hope this isn't too brief for you..

Grtz,
Geert

James Cummings wrote:

Hiya,

I tried to knock up a quick xslt script which would take any script as
its input and generate a very basic xslt stylesheet template.  I.e.
produce something quickly which I could then
edit to make more specific.  Since I already had a script which did an
element count, I stuck that into a variable, and then use the content
in that variable to produce a template for each element name.  (Ok, I
know that wasn't the most efficient way, just what occured to me first
when I threw it together).  Having done that, what is the best way to
include extra rules for specific elements it may or may not come
across.  I've done this by adding <xsl:choose>
for the specific instances.  Better suggestions?
-------------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:key name="gis" match="*" use="name()"/>

<xsl:variable name="tags"> <xsl:for-each select="node()">
<tagsDecl>
<xsl:for-each select="//*[generate-id(.)=generate-id(key('gis',name(.))[1])]">
<xsl:sort select="name()"/>
<tagUsage gi="{name(.)}"><xsl:value-of select="count(key('gis',
name(.)))" /></tagUsage>
</xsl:for-each>
</tagsDecl>
</xsl:for-each>
</xsl:variable>


<xsl:template match="/">
<xsl:element name="xsl:stylesheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:attribute name="version" select="'2.0'"/>
<xsl:element name="xsl:template">
<xsl:attribute name="match" select="'/'"/>
<html> <!-- ok, I'd make this xhtml 1.1 in reality -->
<head><xsl:if test="//title"><title><xsl:value-of
select="//title[1]"/></title></xsl:if></head>
<body>
<xsl:if test="//title"><h1><xsl:value-of select="//title[1]"/></h1></xsl:if>
<xsl:element name="xsl:apply-templates" />
</body>
</html>
</xsl:element>
<xsl:for-each select="$tags/tagsDecl/tagUsage">
<xsl:choose>
<xsl:when test="@gi='div'">
<xsl:element name="xsl:template">
<xsl:attribute name="match" select="@gi"/>
<div class="{@gi}"><xsl:element name="xsl:apply-templates" /> </div>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="xsl:template">
<xsl:attribute name="match" select="@gi"/>
<span class="{@gi}"><xsl:element name="xsl:apply-templates" /></span>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:element>
</xsl:template>

</xsl:stylesheet>
----------------------------


-- Geert.Josten@xxxxxxxxxxx IT-consultant at Daidalos BV, Zoetermeer (NL)

http://www.daidalos.nl/
tel:+31-(0)79-3316961
fax:+31-(0)79-3316464

GPG: 1024D/12DEBB50

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.