Jump to content

aalbetski

Members
  • Posts

    331
  • Joined

  • Last visited

Posts posted by aalbetski

  1. This is an example (fragment) from a project of mine. This was done in C#, but it should point you in the right direction

    XslTransform xsl = new XslTransform();	xsl.Load(MapPath("StyleSheet.xslt"));XsltArgumentList xsltArgs = new XsltArgumentList();xsltArgs.AddParam("ParentTable"	,"","Arg1");xsltArgs.AddParam("ChildTable"	,"","Arg2");this.xmlReport.Document = GetXMLDataSource();this.xmlReport.TransformArgumentList = xsltArgs;this.xmlReport.Transform = xsl;

  2. using XMLDOM, both of these work: document.write(xmlSource.selectSingleNode("//LetterReport/SummaryInfo").getAttributeNode("subAcctName").text); document.write(xmlSource.selectSingleNode("//LetterReport/SummaryInfo/@subAcctName").value);

    xpath

    This will return the max (or min if you change the order to 'ascending') using XSLT

    <xsl:for-each select="//records/id">	<xsl:sort select="." data-type="number" order="descending"/>	<xsl:if test="position()=1">		<xsl:value-of select="."/><br/>	</xsl:if>	</xsl:for-each>

  3. The 'Muenchian' method uses a simple node-set union to determine if an item is unique in a node-set. This example will do what you wish. Note that the | operator is a union of node-sets and not an OR for this application.For a more complete explanation of this, I'll refer you to Jeni Tennison: http://www.jenitennison.com/xslt/grouping/muenchian.html

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ><xsl:output method="html"/><xsl:key name="cats"  match="hmph" use="@cat"/>	<xsl:template match="/">		<xsl:for-each select="//hmph[count(. | key('cats', @cat)[1]) = 1]">			<xsl:value-of select="@cat"/> <br/>		</xsl:for-each>	</xsl:template></xsl:stylesheet>

  4. You can solicit the user input in whatever fashion you desire, a winform, webform, etc.. You would pass that information into the stylesheet as a parameter. I have created a complete working example using javascript and XMLDOM (with IE6.0). You will need to modify based on your enviroment (.NET, ASP, etc..)Sample XML (price.xml)

    <catalog>	<cd>		<name>CD1</name>		<price>10</price>	</cd>	<cd>		<name>CD2</name>		<price>10</price>	</cd>	<cd>		<name>CD3</name>		<price>15</price>	</cd>	<cd>		<name>CD4</name>		<price>15</price>	</cd>	<cd>		<name>CD5</name>		<price>12</price>	</cd></catalog>

    Sample XSL (price.xsl)

    <xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">	<xsl:output method="html"/>	<xsl:param name="price" />	<xsl:template match="/">	   <xsl:for-each select="catalog/cd">			  <xsl:if test="price = $price">				  <xsl:value-of select="name" /><br/>			  </xsl:if>		</xsl:for-each>	</xsl:template></xsl:stylesheet>

    HTML Page that performs transform. Note the value of '10' being passed into the TransformXML() function. This is where you would pass the value to the transformer. How it gets there is up to you.price.html

    <html>	<body onLoad="InitPage()">		<div id="display"></div>	</body>	<script>		function InitPage()		{			document.getElementById("display").innerHTML = 	TransformXML(10)		}		function TransformXML(price)		{			var xmlSource		= 	new ActiveXObject("Msxml2.DOMDocument.4.0")			var xslStyle 		=	new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0")			xmlSource.async 	= 	false			xslStyle.async	=	false			xmlSource.load("price.xml")			xslStyle.load("price.xsl")			xslStyle.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'")			var objTransformer	=	new ActiveXObject("Msxml2.XSLTemplate.4.0")			objTransformer.stylesheet = xslStyle.documentElement			var objProcessor = objTransformer.createProcessor()			objProcessor.addParameter("price",price,"")			objProcessor.input = xmlSource			objProcessor.transform()			return objProcessor.output		}	</script></html>

  5. Using this XML (I guessed at your structure), I first created a node-set of all ImageName nodes. Then simply used the preceding-sibling axis to check for duplicates. I'm sure that this could have been much more elegant using the Muenchian method, but I will leave that to you.XML I used:

    <OrdersByImages>	<ImageOrders>		<ImageName>img01.jpg</ImageName>		<ImageName>img02.jpg</ImageName>		<ImageName>img03.jpg</ImageName>		<ImageNodes><ImageName>img01.jpg</ImageName></ImageNodes>		<ImageNodes><ImageName>img04.jpg</ImageName></ImageNodes>		<ImageNodes><ImageName>img04.jpg</ImageName></ImageNodes>				<ImageNodes><ImageName>img05.jpg</ImageName></ImageNodes>	</ImageOrders></OrdersByImages>

    Stylesheet

    <?xml version="1.0"?><xsl:stylesheet 	version="1.0"	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"	xmlns:msxsl="urn:schemas-microsoft-com:xslt">	<xsl:template match="/"><!-- *************************************** --><!-- Put ALL ImageName nodes into a node-set --> <!-- *************************************** -->		<xsl:variable name="ImageNames">			<xsl:for-each select="//ImageName">				<ImgName>				<xsl:value-of select="." />				</ImgName>			</xsl:for-each>		</xsl:variable><!-- ************************************** --><!-- Return only the unqiue names from that node-set (sorted) --><!-- ************************************** -->		<xsl:for-each select="msxsl:node-set($ImageNames)//ImgName[not(. = preceding-sibling::ImgName)]">			<xsl:sort select="."/>			<xsl:value-of select="."/><br/>		</xsl:for-each>		<hr/>		The count is: 		<xsl:value-of select="count(msxsl:node-set($ImageNames)//ImgName[not(. = preceding-sibling::ImgName)]) " />	</xsl:template></xsl:stylesheet>

    which produces this output

    img01.jpgimg02.jpgimg03.jpgimg04.jpgimg05.jpg--------------------------------------------------------------------------------The count is: 5

    You will note that I used MSXML parser. You will need to change the references to whatever parser you are using

  6. I converted your non-standard number value into a number by first reversing the decimal and thousands separator, than removed the thousands separator. This allowed the values to be sorted as numbers. Give this a try

    <xsl:apply-templates select="via">	  <xsl:sort select="translate(translate(amount,'.,',',.'),',','')" data-type="number" /></xsl:apply-templates>

    The inside translate does the switch of separators. The ouside one removed the thousands separtor so that it can be interpreted as a numberHope this helps

  7. Take advantage of @media This should do what you want for all browsers:<style>@media Print{ div#navigation { display:none }}@media Screen{ div#navigation { display:block}}</style><div id="navigation"><ul><li><a href="R home.asp">R home</a></li><li><a target="_blank" href="retail%20list2.pdf">Bonus List</a></li><li><a href="posters.asp">Posters</a></li><li><a href="faqs.asp">FAQs</a></li><li><a href="cheques.asp">cheques</a></li><li><a href="info">Sign in</a></li><li><a href="calander.asp">Calendar</a></li><li><a href="terms.asp">Ts & Cs</a></li></ul></div>

×
×
  • Create New...