BlueDigit Posted January 26, 2010 Share Posted January 26, 2010 Let's say you want to generate a set of divs like this— <div class="specialDiv" id="uniqueId1" onclick="clickFunction('uniqueId1', 'uniqueId2');" onmouseover="mouseFunction('uniqueId1', 'uniqueId2');" onmouseout="mouseFunction('uniqueId2', 'uniqueId1');">text</div><div class="specialDiv" id="uniqueId2" onclick="clickFunction('uniqueId2', 'uniqueId1');" onmouseover="mouseFunction('uniqueId2', 'uniqueId1');" onmouseout="mouseFunction('uniqueId1', 'uniqueId2');">text</div> —from an XML document that uses the same tags for both divs. I'm aware that this is possible to do (example), and I have managed to get it working that far, but the problem lies in something else: I can't get the attributes to carry over with the tags. Placing an XSLT tag (xsl:copy-of, xsl:value-of…) inside the div where the attributes would be causes an error, and using </> for the div turns the HTML to standard text. I've tried messing around with xsl:variable and xsl:element, too, without success on either attempts. What am I missing? Link to comment Share on other sites More sharing options...
Martin Honnen Posted January 26, 2010 Share Posted January 26, 2010 You have posted a fragment of the output you want to create but you have not shown the input. Please show is the input you want to create the output from. Link to comment Share on other sites More sharing options...
BlueDigit Posted January 27, 2010 Author Share Posted January 27, 2010 You have posted a fragment of the output you want to create but you have not shown the input. Please show is the input you want to create the output from. 'K, then.XML:<?xml version="1.0" encoding="UTF-16"?><?xml-stylesheet type="text/xsl" href="C:\Documents and Settings\admin\My Documents\Web pages\test.xsl"?><base xmlns:xlink="http://www.w3.org/1999/xlink"><listUnit> <displayTitle>Test 1</displayTitle> <cssTitle>games</cssTitle> <ecmaTitle>games</ecmaTitle> <indexNumber>0</indexNumber> <content> <listGroup sorter="0"> <linkUnit> <linkText>Test Link 1</linkText> <linkTo>http://www.neopets.com/</linkTo> <sorter>0</sorter> </linkUnit> <linkUnit> <linkText>Test Link 3</linkText> <linkTo>http://www.neopets.com/</linkTo> <sorter>2</sorter> </linkUnit> <linkUnit> <linkText>Test Link 2</linkText> <linkTo>http://www.neopets.com/</linkTo> <sorter>1</sorter> </linkUnit> </listGroup> </content></listUnit><listUnit> <displayTitle>Test 2</displayTitle></listUnit></base> XSLT: <?xml version="1.0" encoding="UTF-16"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" version="4.0" encoding="UTF-16" omit-xml-declaration="no" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" media-type="text/xml" /> <xsl:param name="listUnitGroup" select="2" /> <xsl:param name="displayTitleGroup" /> <xsl:param name="cssTitleGroup" /> <xsl:param name="ecmaTitleGroup" /> <xsl:param name="linkGroup" /><xsl:template match="base"><html lang="en" dir="ltr" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test Portal</title> <meta charset="UTF-16" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-16" /> <meta http-equiv="Date" content="22-01-2010" scheme="DD-MM-YYYY" /> <meta http-equiv="Last-Modified" content="22-01-2010" scheme="DD-MM-YYYY" /> <link href="…" type="text/css" rel="stylesheet" /> </head> <body> <div style="border: 5px solid #000000;"> <xsl:apply-templates select="listUnit[(position() mod $listUnitGroup) = 1]" /> </div> </body></html></xsl:template><xsl:template match="listUnit"> <xsl:variable name="id"> id="<xsl:value-of select="ecmaTitle" />" </xsl:variable> <xsl:variable name="headBgCon"> onmouseover="headBgCon('<xsl:value-of select="ecmaTitle" />', 1);" onmouseout="headBgCon('<xsl:value-of select="ecmaTitle" />', 2);" </xsl:variable> <xsl:variable name="boxConO"> onclick="boxCon('<xsl:value-of select="ecmaTitle" />Content', '<xsl:value-of select="ecmaTitle" />Header');" </xsl:variable> <xsl:variable name="boxConC"> onclick="boxCon('<xsl:value-of select="ecmaTitle" />Header', '<xsl:value-of select="ecmaTitle" />Content');" </xsl:variable> <xsl:for-each select=". | following-sibling::listUnit[position() < $listUnitGroup]"> <div class="ocBox_container"> <div class="ocBox_headerContain" <xsl:copy-of select="$id" />> <div class="ocBox_header" <xsl:copy-of select="$headBgCon" /> <xsl:copy-of select="$boxConO" />> <span style="font-weight: bold"><xsl:value-of select="displayTitle" /></span><br /> </div> </div> </div> </xsl:for-each></xsl:template></xsl:stylesheet> Ignore the unused elements and extra parameters, they're for after I get the basics working. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.