Jump to content

xslt functions / debugging


bistritapcv

Recommended Posts

I was following the w3 tutorials and examples and trying to do my own with moderate success.Certain functions worked, like concat(), but other functions would not work, like index-of() though itwas mentioned in the http://www.w3schools.com/xpath/xpath_functions.asp#sequence. As a matterof fact, none of the sequence functions worked, nor none of the date functions. And they justgave me a message either bad xslt function or simply "null". I also tried writing some of my ownfunctions (based on examples) but those did the same thing. The error messages were not verydescriptive.Anyway to do better debugging? Better still, anyone know what is wrong with what I have below?I took out the calls to my functions, for debugging. The index-of doesn't work either. When I removecalls to it and to my functions I get some output (this is not really my CD collection. That linewas left over from an example).Here is my XSLT code<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="2.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:function name="local:tony"> <xsl:param name="sys"/> <xsl:value-of select="compare(upper-case($sys),'GSM')"/></xsl:function><xsl:function name="foo:compareCI"> <xsl:value-of select="32" /></xsl:function><xsl:template match="/"><html><body><h2>My CD Collection</h2><xsl:for-each select="BILL/RECORD"> <xsl:value-of select="@SEQ"/><p/> <xsl:variable name="cleesys" select="CALLEE/@System"/> <xsl:variable name="clersys" select="CALLER/@System"/> <xsl:value-of select='concat("XCALLER: " , $clersys)'/><p/> <xsl:value-of select='concat("XCALLEE: " , $cleesys)'/><p/> <xsl:value-of select='index-of( (10,20,30,20,30,10,30,40), 30 )' /></xsl:for-each></body></html></xsl:template></xsl:stylesheet>[/font]and one record of my xml:<?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="bill.xsl"?><BILL GenData="" type="VOICE"><RECORD SEQ="00002" Opcode="O"> <CALL-TYPE>T</CALL-TYPE> <CALLER Type="HLR" Prepaid="Y" System="GSM"> <MDN>6303550515</MDN> <IMSI>310006303550515</IMSI> <EQUIP-ID>Equip1</EQUIP-ID> </CALLER> <CALLEE Type="HLR" System="SIP"> <MDN>6168464396</MDN> <IMSI>460166168464396</IMSI> <EQUIP-ID>Equip2</EQUIP-ID> </CALLEE> <CALL-LOCATION> <ORIG> <DMA-IP>100.200.300.400</DMA-IP> <CELL-ID>Cell01</CELL-ID> <LAC>MyLac</LAC> </ORIG> <TERM> <DMA-IP>111.222.333.444</DMA-IP> <CELL-ID>Cell02</CELL-ID> <LAC>NoLac</LAC> </TERM> </CALL-LOCATION></RECORD>The output (when I remove the index-of line)(For brevity I listed only 1 record above. There are actuallymore as you can see below):My CD Collection00002XCALLER: GSMXCALLEE: SIP00003XCALLER: CDMAXCALLEE:

Link to comment
Share on other sites

If you look closely, you'll see the XPath reference is a XPath 2.0 reference. The problem is XPath 2.0 adds many new functions which can't be executed in XPath 1.0, which is the only version supported in browsers, and a variery of server side XSLT processors as well.I personally use up Dreamwaver's reference to check for XSLT funcitons. It lists only XPath 1.0 functions, but at least I know they'll work.I also somethimes use a reference of my own I made to benchmark what functions and elements are available in what processors. Below are the results of SAXON8-B:http://boenrobot1.hit.bg/benchmarks/Saxon8-B.html

Link to comment
Share on other sites

Actually, I don't have to do this with HTML at all. As a matter of fact something else might be better.I am trying to take the values from XML (say, given this simplified example):<BILL> <RECORD> <CALLER> <PHONE>8005882300</PHONE> <IMSI>310008005882300</IMSI> </CALLER> <CALLEE> <PHONE>3128675309</PHONE> <IMSI>460173128675309</IMSI> </CALLEE> <DATE>20071112200112</DATE> </RECORD></BILL>make a fixed-width datafile like2007111220011280058823003100080058823003128675309460173128675309(etc. for subsequent records).Is there a better language that has good XML-handling functions?

Link to comment
Share on other sites

All modern languages have good XML capabilities by the use of DOM, but they are all "locked" into themselves, whereas XSLT can be used anywhere.If that's not a problem with you, use any language you're comfortable with. Chances are it has XML tools already. If not natively, surely with an add on.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...