effective xslt

17
#RefreshCache Effective XSLT Making use of XSLT to better customize your data. Daniel Hazelbaker Information Technology Manager High Desert Church Email: [email protected]

Upload: claude

Post on 06-Jan-2016

17 views

Category:

Documents


0 download

DESCRIPTION

Effective XSLT. Making use of XSLT to better customize your data. Daniel Hazelbaker Information Technology Manager High Desert Church Email: [email protected]. What is XSLT?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Effective XSLT

#RefreshCache

Effective XSLT

Making use of XSLT to better customize your data. Daniel Hazelbaker

Information Technology ManagerHigh Desert Church

Email: [email protected]

Page 2: Effective XSLT

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.

Page 3: Effective XSLT

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

Page 4: Effective XSLT

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 />

Page 5: Effective XSLT

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.

Page 6: Effective XSLT

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”

Page 7: Effective XSLT

Using ‘if’ statements<xsl:if test="@meetingstarttime != '12:00 AM'"> <xsl:text> </xsl:text> <xsl:value-of select="@meetingstarttime"/></xsl:if>

Page 8: Effective XSLT

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

Page 9: Effective XSLT

Using Parameters<xsl:param name="detailsAsPopup">no</xsl:param>

<xsl:if test="$detailsAsPopup = 'yes'"> <xsl:text disable-output-escaping="yes"><![CDATA[<script type="text/javascript">...</script>]]> </xsl:text></xsl:if>

Page 10: Effective XSLT

Looping through a list<xsl:for-each select="group"> <xsl:sort select="@name"/> <div class="sgl_row"> <span class="sglr_name"> <xsl:value-of select="@name"/> </span> <span class="sglr_info"> <xsl:attribute name="data-id"> <xsl:value-of select="@id"/> </xsl:attribute> <xsl:text>More Info</xsl:text> </span> </div></xsl:for-each>

Page 11: Effective XSLT

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

Page 12: Effective XSLT

Comparison Operators• and Logical-and (&&)

author[degree and award]

• or Logical-or (||) author[degree or award]

• = Equality (==) @attribute = ‘yes’

• != Not equal (!=) @attribute != ‘yes’

Page 13: Effective XSLT

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]

Page 14: Effective XSLT

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()

Page 15: Effective XSLT

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

Page 16: Effective XSLT

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

Page 17: Effective XSLT

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