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

check for existance of an element in the xml

Subject: check for existance of an element in the xml
From: Jake The Snake Briggs <jakbri@xxxxxxxxxxxxxx>
Date: Tue, 07 Dec 2004 18:24:28 +1300
html groupbox
HI all
I would to check for the existance of an element, and act upon it, rather than act everytime the element is matched. What i mean is I have xml that describes how a web page looks, and an xsl that transforms that to html and javascript.


For example, i may have this :

<page>
<groupbox x="10" y="10">
<text value="Blaa Blaa" x="10" y="10"/>
<input x="10" y="20" name="foo"/>
</groupbox>
<groupbox x="10" y="30">
<text value="Something Else" x="10" y="10"/>
<input x="10" y="20" name="bar"/>
</groupbox>
<input x="10" y="50" name="gle"/>
</page>


The issue is that at the moment i have some javascript that operates on the input fields, so I am including it everytime I produce a page, but I want to only include it iff the xml has at least one <input .../> element. This is of course simplified, the real xml and the html it produces is a lot more complicated, some of the html pages produced are getting fairly large :)
The xsl root match is where i am including all the various javascript files. Here is a simplified version of my xslt, for those who dont do html :


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>


<xsl:template match="/">
<html>
<head>
<script language="JavaScript" src="Shared/Javascript/validate.js"></script>
</head>
<body> <xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="input">
<!-- input field code goes here -->
</xsl:template>
.
.
.
</xsl:stylesheet>


I only want that <script language="JavaScript" src="Shared/Javascript/validate.js"></script> part to appear once in the resulting html iff the xml i am processing has at least one <input..../> element. I figure i can parse the xml twice, but i cant work out how i would only match unique elements the first time :) What sort of thing should i be googleing for in order to solve this problem, it seems like the sort of thing people would want to do....

Jake

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.