Jump to content

Help - Javascript Inside Xslt


jp5

Recommended Posts

Hi, Am new to this forum (as well as xml - so sorry for any unsightly code) and hoping someone can point me in the right direction. I have this code formatting an xml file in a CSV manner. It creates the folder name (which is a web address), followed by the value of slides - which is the number of files in that folder (call x). What I'd like is to implement a loop (int i=1, i<=x, i++), so that a new line is created with the name of the folder, followed by "/image" + i +".png" - i,e. every file in that folder has it's address on a new line of code. Currently:www.blah.com/bananas , 2www.blah.com/apples , 3 Desired:www.blah.com/bananas/image1.pngwww.blah.com/bananas/image2.pngwww.blah.com/apples/image1.pngwww.blah.com/apples/image2.pngwww.blah.com/apples/image3.png Is this possible with some javascript? Any help is much appreciated. Many thanks,Jack ---------------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"><html><body><xsl:for-each select="//folder"> <xsl:value-of select="."/> , <xsl:value-of select="../slides"/> <br /></xsl:for-each></body></html></xsl:template> </xsl:stylesheet>-----------------------------------------------------------------------------

Link to comment
Share on other sites

Here is an example XML

<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?><!DOCTYPE introduction SYSTEM "dtd/documentation.dtd"><document xmlns:xhtml="http://www.w3.org/1999/xhtml">		   <data id="introduction" status="Complete" type="example">			   <title>Introduction</title>				 <p>Content goes here</p>				 <image name="example">This is text associated with an image</image>				 <note>This is an example of a note.</note>		   </data></document>

And here is the XSL. The script tags causing the issue have been removed as has HTML5 doctype (It altered my CSS).

<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet			   version="1.0"			   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"			   xmlns:xhtml="http://www.w3.org/1999/xhtml"><xsl:variable name="authors" select="document('authors.xml')"/><xsl:key name="k1" match="author" use="@doc"/><!-- Doctype - about:legacy-compat is XML equivalent of HTML5 doctype --><xsl:output method="html" indent="yes"			 omit-xml-declaration="yes"			 doctype-public="about:legacy-compat"/><xsl:template match="document"><html xmlns="http://www.w3.org/1999/xhtml"	   xml:lang="en" lang="en"><head><title>Documentation</title>  <link type="text/css" rel="stylesheet" href="css/documentation.css"/>  <link type="text/css" rel="stylesheet" href="css/lightbox.css" media="screen"/>  <link type="text/css" rel="stylesheet" href="css/jquery.qtip.min.css"/>  <link type="text/css" rel="stylesheet" href="css/jquery.qtip.css"/>   <xsl:text disable-output-escaping="yes"> <![CDATA[   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>   <script type="text/javascript" src="js/prototype.js"></script>   <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>   <script type="text/javascript" src="js/lightbox.js"></script>   <script type="text/javascript" src="js/jquery.qtip.js"></script>   <script type="text/javascript" src="js/jquery.qtip.min.js"></script>   <script type="text/javascript" src="js/invoke.js"></script> ]]>  </xsl:text> </head><body>   <xsl:apply-templates/></body></html></xsl:template>			   <!-- This section will lookup HTML tags within the XML document forward to HTML as tag --><xsl:template match="p">   <xsl:copy>	  <xsl:apply-templates/>   </xsl:copy></xsl:template><xsl:template match="br">   <xsl:copy>	  <xsl:apply-templates/>   </xsl:copy></xsl:template><xsl:template match="ul">   <xsl:copy>	  <xsl:apply-templates/>   </xsl:copy></xsl:template><xsl:template match="li">   <xsl:copy>	  <xsl:apply-templates/>   </xsl:copy></xsl:template><xsl:template match="table">   <xsl:copy>	  <xsl:apply-templates/>   </xsl:copy></xsl:template><xsl:template match="tr">   <xsl:copy>	  <xsl:apply-templates/>   </xsl:copy></xsl:template><xsl:template match="td">   <xsl:copy>	  <xsl:apply-templates/>   </xsl:copy></xsl:template><xsl:template match="th">   <xsl:copy>	  <xsl:apply-templates/>   </xsl:copy></xsl:template><!-- End of HTML tag lookup --><xsl:template match="note">   <br>	   <div id="note">		  Notes:		  <br>			 <xsl:apply-templates/>		  </br>	   </div>   </br></xsl:template><xsl:template match="link">   <a href="{.}.xml">	  <xsl:apply-templates/>   </a></xsl:template><xsl:template match="image">   <div class="image">	  <a title="{.}" rel="lightbox"					 href="images/{@name}_large.jpg">		 <img title="{@name}" src="images/{@name}_thumb.jpg"/>	  </a>		 <div>			<xsl:value-of select="@name"/>		 </div>   </div></xsl:template><xsl:template match="data">   <xsl:variable name="id" select="@id"/>	  <xsl:apply-templates/>   <!-- for XSLT 1.0 need to change context document with for-each				 with XSLT 2.0 could simply use key('k1', $id, $authors) -->	  <xsl:for-each select="$authors">		 <xsl:variable name="referenced-authors" select="key('k1', $id)"/>		   <xsl:if test="$referenced-authors">			  <br>				 <table class="authors">					<th class="authors">Document authors</th>					<xsl:apply-templates select="$referenced-authors"/>				 </table>			  </br>		   </xsl:if>	  </xsl:for-each></xsl:template><xsl:template match="author">   <tr class="authors">	  <xsl:apply-templates select="name"/>		 <a href="mailto:{email}"><xsl:apply-templates select="email"/> </a>		 <a href="http://www.{@company}.com" target="_blank"><xsl:apply-templates select="@company"/></a>   </tr></xsl:template><xsl:template match="author/* | author/@company">   <td class="authors">	  <xsl:value-of select="."/>   </td></xsl:template><xsl:template match="title">   <h1><xsl:apply-templates/></h1></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...