[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: check for existance of an element in the xml
I underlined the change with "*". The changed XSLT is: <?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> * <xsl:if test="//input"> <script language="JavaScript" src="Shared/Javascript/validate.js"></script> * </xsl:if? </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="input"> <!-- input field code goes here --> </xsl:template> . . . </xsl:stylesheet> --- Jake The Snake Briggs <jakbri@xxxxxxxxxxxxxx> wrote: > 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 > > ===== Marian http://www.utdallas.edu/~mgo031000/ __________________________________ Do you Yahoo!? Take Yahoo! Mail with you! Get it on your mobile phone. http://mobile.yahoo.com/maildemo
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|