1 / 17

Effective XSLT

Effective XSLT. Making use of XSLT to better customize your data. Daniel Hazelbaker Information Technology Manager High Desert Church Email: daniel@highdesertchurch.com. What is XSLT?.

claude
Download Presentation

Effective XSLT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Effective XSLT Making use of XSLT to better customize your data. Daniel Hazelbaker Information Technology Manager High Desert Church Email: daniel@highdesertchurch.com

  2. What is XSLT? • XSLT is used to transform an XML document into another XML document, or another type of document that is recognized by a browser, like HTML. • XSLT uses XPath to reference the elements inside the XML document.

  3. Common Element Functions • <xsl:attribute /> • <xsl:text /> • <xsl:value-of /> • <xsl:copy />

  4. Full Element Function List • <xsl:decimal-format /> • <xsl:key /> • <xsl:choose /> • <xsl:if /> • <xsl:otherwise /> • <xsl:when /> • <xsl:attribute /> • <xsl:attribute-set /> • <xsl:comment /> • <xsl:copy /> • <xsl:element /> • <xsl:namespace-alias /> • <xsl:number /> • <xsl:processing-instruction /> • <xsl:text /> • <xsl:value-of /> • <xsl:preserve-space /> • <xsl:strip-space /> • <xsl:fallback /> • <xsl:message /> • <xsl:call-template /> • <xsl:output /> • <xsl:for-each /> • <xsl:sort /> • <xsl:import /> • <xsl:include /> • <xsl:stylesheet /> • <xsl:transform /> • <xsl:apply-imports /> • <xsl:template /> • <xsl:copy-of /> • <xsl:param /> • <xsl:variable /> • <xsl:with-param />

  5. XSLT/XPath Basics • “group” • All node elements whose name is “group” • “@name” • The “name” attribute of the current node • “group[@active = 1]” • All node elements whose name is “group” and has an attribute called “active” whose value is 1.

  6. XSLT/XPath Basics (cont.) • “group/member” • All node elements whose name is “member” and whose parent node name is “group” (that is, all group members). • “group[@active = 1]/member[@firstname= ‘Daniel’]” • All small group members whose first name is “Daniel” and is a member of a currently active group. • “group[@active = 1 and contains(@name, ‘Victorville’)]” • All small groups which are active and whose name contains the word “Victorville”

  7. Using ‘if’ statements <xsl:iftest="@meetingstarttime != '12:00 AM'"> <xsl:text> </xsl:text> <xsl:value-ofselect="@meetingstarttime"/> </xsl:if>

  8. Using ‘choose’ statements <xsl:choose> <xsl:whentest="@status = 'Green'"> <imgsrc="ok.png"alt="" /> </xsl:when> <xsl:whentest="'@status = 'Red'"> <imgsrc="error.png"alt="" /> </xsl:when> <xsl:otherwise> <imgsrc="unknown.png"alt="" /> </xsl:otherwise> <xsl:choose>

  9. Using Parameters <xsl:paramname="detailsAsPopup">no</xsl:param> <xsl:iftest="$detailsAsPopup = 'yes'"> <xsl:textdisable-output-escaping="yes"><![CDATA[ <script type="text/javascript"> ... </script> ]]> </xsl:text> </xsl:if>

  10. Looping through a list <xsl:for-eachselect="group"> <xsl:sortselect="@name"/> <divclass="sgl_row"> <spanclass="sglr_name"> <xsl:value-ofselect="@name"/> </span> <spanclass="sglr_info"> <xsl:attributename="data-id"> <xsl:value-ofselect="@id"/> </xsl:attribute> <xsl:text>More Info</xsl:text> </span> </div> </xsl:for-each>

  11. Embedding Javascriptor CSS <xsl:textdisable-output-escaping="yes"><![CDATA[ <script type="text/javascript"> $(document).ready(function() { alert('Document is ready!'); }); </script> ]]></xsl:text>

  12. Comparison Operators • and Logical-and (&&) author[degree and award] • or Logical-or (||) author[degree or award] • = Equality (==) @attribute = ‘yes’ • != Not equal (!=) @attribute != ‘yes’

  13. Comparison Operators (cont.) • &lt; Less than (<) book[@price &lt; 20] • &lt;= Less than or equal (<=) book[@pages &lt;= 400] • &gt; Greater than (>) book[@price &gt; 20] • &gt;= Greater than or equal (>=) book[@pages &gt;= 400]

  14. XPath Functions • count() • id() • last() • local-name() • name() • namespace-uri() • position() • concat() • contains() • normalize-space() • starts-with() • string() • string-length() • substring() • substring-after() • substring-before() • translate() • boolean() • false() • lang() • not() • true() • ceiling() • floor() • number() • round() • sum()

  15. Counting Tiny Small Groups <span> There are <xsl:value-ofselect="count(//group[@membercount&lt; 6])" /> small groups with less than 6 members. </span>

  16. Debugging for-each loops <xsl:for-eachselect="//group"> <xsl:iftest="$debug = 1"> <div> Processing element number <xsl:value-ofselect="position()" /> of <xsl:value-ofselect="count(//group)" /> </div> </xsl:if> ... </xsl:for-each>

  17. Cheat Sheets • http://www.refcards.com/subject/xml • XPath by DeepX Ltd • XSLT 1.0 Quick Reference by DeepX Ltd

More Related