Example: stock market

XSLT Reference

xslt ReferenceJohn W. Shipman2013-07-3011:50 AbstractDescribesthe xslt languagefor availablein Webform1and alsoas a PDFdocument2. of Contents1. Whatis xslt ?.. 22. A 33. Namespacesand 54. Datatypesin Axisselectionin 125. 126. The rootelement<xsl:stylesheet>.. <xsl:stylesheet> 137. <xsl:output>: <xsl:preserve-space>: <xsl:strip-space>: <xsl:import>: Use <xsl:key>: Createan indexto <xsl:decimal-format>: Definea 168. <xsl:template>: Definea <xsl:variable>: Definea globalor <xsl:apply-templates>: Processa nodeset <xsl:include>: <xsl:param>: Definean argumentto be passedinto a <xsl:with-param>: Passan argumentto a 199. <xsl:text>: Outputliteraltext.

XSLT is not like a programming language: it is not sequentially executed. Instead, an XSLT script is a specificationof how the output looks as a function of input.

Tags:

  Reference, Xslt, Xslt reference

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of XSLT Reference

1 xslt ReferenceJohn W. Shipman2013-07-3011:50 AbstractDescribesthe xslt languagefor availablein Webform1and alsoas a PDFdocument2. of Contents1. Whatis xslt ?.. 22. A 33. Namespacesand 54. Datatypesin Axisselectionin 125. 126. The rootelement<xsl:stylesheet>.. <xsl:stylesheet> 137. <xsl:output>: <xsl:preserve-space>: <xsl:strip-space>: <xsl:import>: Use <xsl:key>: Createan indexto <xsl:decimal-format>: Definea 168. <xsl:template>: Definea <xsl:variable>: Definea globalor <xsl:apply-templates>: Processa nodeset <xsl:include>: <xsl:param>: Definean argumentto be passedinto a <xsl:with-param>: Passan argumentto a 199. <xsl:text>: Outputliteraltext.

2 191 <xsl:value-of>: Outputthe valueof an <xsl:element>: Outputan <xsl:attribute>: Outputan <xsl:number>: Outputan elementnumberor 2110. <xsl:for-each>: Iterateovera set of <xsl:if>: <xsl:choose>: The <xsl:call-template>: 2311. <xsl:apply-imports>: Use an <xsl:attribute-set>: Definea namedattributeset .. <xsl:comment>: Outputa <xsl:copy>: <xsl:copy-of>: <xsl:fallback>: Whatto do if an extensionis <xsl:message>: Writea <xsl:namespace-alias>: Assigna prefixto a <xsl:processing-instruction>: Outputa <xsl:sort>: Processnodesin a 2512. (): Returnthe (): Pullin (): Converta numberto a (): Generatea (): Referto an (): Returna 2813.

3 2814. 2915. 301. What is xslt ?XSLTis a tool for transformingan XML(eXtendedMarkupLanguage)documentinto eitheran HTML document,or into an XMLdocumentof a you are familiarwiththe structureof XMLdocuments;if you are unfamil-iar withXML,see the the examplesuse HTML;for Reference ,seeBuildingweb this document: : Thisfile is the skeletonof an xslt stylesheetfor convertingan starta newstylesheet,makea copyof thisfile and add yourtitle and templates. : The XMLDocBooksourcefile for the documentyou are A briefexampleXSLTis not like a programminglanguage:it is not ,an xslt scriptis aspecificationof howthe outputlooksas a functionof basicunitis thetemplate; a templateusuallydefineshowone particulartypeof XMLtag is to be the TechComputerCenter,we haveinstalleda Unixprogramcalledxsltprocthat will processanXSLT script,transforminga givenXMLfile into an outputfile in eitherHTMLor the a smallexampleXMLfile that describeshikingtrailsinsidea park:<!

4 DOCTYPE parkSYSTEM" "> <parkname="LincolnNaturalForest"> <traildist="3400"climb="medium">CanyonTrail</trail> <trailclimb="easy"dist="1200">PickleMaddenTrail</trail> </park>The rootelementis<park>. It contains<trail>elements,eachdescribingone wantto translatethis to HTML that lookslike this:<html> <head> <title>LocalHikingTrails</title> </head> <body> <ul> <li>CanyonTrail:3400feet,climbmedium</li> <li>PickleMaddenTrail:1200feet,climbeasy</li> </ul> </body> </html>Hereis an xslt scriptthat doesit:<?xmlversion=" "?> <xsl:stylesheetversion=" "xmlns:xsl=" "> <xsl:outputmethod="html"/> <!--Thistemplateprocessesthe rootnode("/")--> <xsl:templatematch="/"> <!--Tagswithno xsl:prefixare copiedto the output--> <html> <head> <title>LocalHikingTrails</title> </head> <body> <ul> <!

5 --Tagsthatstartwithxsl:are instructionson how! to translatethe says,! translateall the <trail>elementsusingthe! appropriatetemplate(below).!--> <xsl:apply-templatesselect="park/trail"/>3 XSLTR eferenceNewMexicoTechComputerCenter</ul> </body> </html> </xsl:template> <!--Thistemplateis usedto translatethe <trail>elements.!--> <xsl:templatematch="trail"> <li> <!--Starta new listitem--> <!--Outputthe textinsidethe <trail>element--> <xsl:value-ofselect="."/> <!--Outputa colonand a space--> <xsl:text>:</xsl:text> <!--The nexttag outputsthe valueof the trailelement's! "dist="attribute.!--> <xsl:value-ofselect="@dist"/> <xsl:text>feet,climb</xsl:text> <xsl:value-ofselect="@climb"/> </li> <!--End of the listitem--> </xsl:template> </xsl:stylesheet>Thefirstline identifiesthefile as XML:<?

6 Xmlversion=" "?>The nexttag identifiesthefile as an XSLstylesheet,and givesthe URLof the xslt standard:<xsl:stylesheetversion=" "xmlns:xsl=" ">The nextline is an XSLTtag statingthat the outputshouldbe expressedin HTMLand not in XML:<xsl:outputmethod="html"/>The rest of thefile consistsof the attributematch="/", whichmeansthat the templateappliesto the rootof the "/"partis an expressionin the XPathlanguage,describedin the XPathsectionbelow,that selectsthe rootof the thinginsidethis root templateis a seriesof HTML tags like<html>,<head>, and so on. Becausethesetag namesdon'tstartwithxsl:, theyare copieddirectlyto the HTML outputfile. Notethe<ul>elementthatwrapsthe wholepagecontentin a bulletlist.

7 The<li>elementsinsideit willbe bodyof the HTML page,insidethe<body>element,is createdby this line:<xsl:apply-templatesselect="park/trail"/>Thistag instructsthe xslt processorto go offandfind a templatethat appliesto the<trail>elementsinsidethe<park>at the document'stop resultsof applyingthat templateare insertedat thispointin the remainderof the roottemplate,wefindthe beginningof the usedto translate<trail>elements:NewMexicoTechComputerCenterXSLT R eference4<xsl:templatematch="trail">Thematch="trail"attributeusesXPathto select<trail> withthe othertemplate,thetagsinsidethis templatethat don'tstartwithxsl:are copiedto the templateis the<li>openingtag that will surroundthe contentfor this lineand makeit a bulletin the<ul> nextthingwe wantto addto the HTML pageis the nameof the the XMLinput,the trailnameis the text betweenthe<trail>and</trail> XPathexpressionfor the contentof anodeis".

8 ", and the<xsl:value-of>tag is usedto insertthat contentinto the outputfile:<xsl:value-ofselect="."/>The nextXSLT elementoutputsa colonand a spaceto the HTML pagewe are building:<xsl:text>:</xsl:text>To outputthe valueof thedist=".."attribute,we againuse<xsl:value-of>. Thistimethe XPathexpressionselectsan attributeof the contextnode(whichis<trail>insidethis template)by usingthe@operator:<xsl:value-ofselect="@dist"/>Thisexamplewill giveyou the generalflavorof XPathexpressionlanguageusedin xslt (andin otherXML-basedtools),we'llmoveon to the Namespaces and XSLTS incethe xslt stylesheetand thefile it operateson are bothXMLdocuments,we needsomewaytodistinguishbetweenmorethano ne set of of namesis solutionto this problemis to definea two-partelementname:< >wherenamespacedefineswhichset of elementnameswe'retalkingabout,andelement -nameis theelementnameinsidethat an xslt stylesheet,any elementnamethat doesn'thaveanxsl.

9 Prefixrepresentsan element(withits content,if any)that getswrittento the :namespaceand the namespaceof the elementsyou are writingto the output,you mayalsouse controlwhichnamespacesare outputand whichare actedon: seethe sectionon the attributesof the rootelement, an exampleof a situationwhereyou needto referto othernamespaces,see the sectionon moreinformation,see the referencefor XPath referenceThe XPathlanguageis usedto describelocationsin a is the expressionlanguageusedby the XPathspecification8for well-formedXMLdocumentcan be visualizedas a tree (in the computersciencemeaningof the term),andthis viewis example,if a certaindocumentrepresentsabook,it mighthavea top-leveltag<book>, containingelementslike<chapter>and<appendix>.

10 A few importantdefinitions: Anodeis the basicbuildingblockof the documenttree,thatis, the datastructureusedto representan XMLdocumentduringits processingby an xslt script. The noderepresentingthe outermosttag of the documentis calledtheroot nodeof the tree. All nodesexceptthe rootnodeof the tree haveaparentnode, and manynodescan continuethe exampleabove,the<book>nodeis the root,andits childrenare the<chapter>and<appendix>elements. All XPathexpressionsare evaluatedin the contextof a particularnode(location)in the calledthecontextnode. Thecontextsizeis the numberof childrenof the contextnode' example,if the contextnodeis one of sevenchildrenof its parent,the contextsize is seven. Thecontextpositionis the childnumberof the contextnoderelativeto its example,if thecontextnodeis the thirdof sevenchildrenof its parent,its contextpositionis Data typesin XPathXPathexpressionsuse thesedatatypes:node-setManyXPathoperatio nsselecta set of zeroor example,the expression"address"selectsall of the<address>elementsthatare childrenof the nodes,one node,or trueor XPathare stringof NodetypesThesetypesof nodesare usedto representa documentas a tree.


Related search queries