260 likes | 440 Views
XSL-2. COSC643 Internet Supply-Chain Management Sungchul Hong. Last Class. DTD XSL Template <xsl:value-of <xsl:apply-templates>. Today. More XSL List elements. Passing the Node for Further Processing. <?xml version="1.0"?>
E N D
XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong
Last Class • DTD • XSL • Template • <xsl:value-of • <xsl:apply-templates>
Today • More XSL • List elements
Passing the Node for Further Processing • <?xml version="1.0"?> • <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> • <xsl:template match="*"> • <xsl:apply-templates /> • </xsl:template> • <xsl:template match="text()"> • <DIV style="border: solid 1px"> • <xsl:value-of select="." /> • </DIV> • </xsl:template> • <xsl:template match="/"> • <div style="border: solid 3px; padding: 10px;"> • <xsl:apply-templates /> • </div> • </xsl:template> • </xsl:stylesheet>
Getting Specific • <?xml version="1.0"?> • <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> • <xsl:template match="/"> • <xsl:apply-templates /> • </xsl:template> • <xsl:template match="*"> • <xsl:apply-templates /> • </xsl:template> • <xsl:template match="text()"> • <xsl:apply-templates /> • </xsl:template> • <xsl:template match="vendor_name"> • <p><xsl:value-of select="." /></p> • </xsl:template> • </xsl:stylesheet>
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template match="*"> <xsl:apply-templates /> </xsl:template> <xsl:template match="text()"> <xsl:apply-templates /> </xsl:template> <xsl:template match="product"> <ul><li> <xsl:value-of select="product_id" />: <xsl:value-of select="short_desc" /> </li></ul> </xsl:template> <xsl:template match="vendor_name"> <p><xsl:value-of select="." /></p> </xsl:template> </xsl:stylesheet>
<xsl:template match="product"> <ul><li> <xsl:apply-templates select="product_id" /> <xsl:value-of select="short_desc" /> </li></ul> </xsl:template> <xsl:template match="product/product_id"> <xsl:value-of select="." />: </xsl:template> <xsl:template match="vendor_name"> <p><xsl:value-of select="." /></p> </xsl:template>
<xsl:template match="product"> <ul><li> <xsl:apply-templates select="product_id" /> <xsl:value-of select="short_desc" /> <br /><xsl:apply-templates select="inventory[@color]"/> </li></ul> </xsl:template> <xsl:template match="inventory[@color]"> -- <xsl:value-of select="@color" /> <br/> </xsl:template> <xsl:template match="product/product_id"> <xsl:value-of select="." />: </xsl:template> <xsl:template match="vendor_name"> <p><xsl:value-of select="." /></p> </xsl:template> Displaying Attributes
Checking for a Specific Attribute Values • <xsl:template match=“inventory[@color and @location=‘warehouse’]”>
<xsl:template match="product"> <ul><li> <xsl:apply-templates select="product_id" /> <xsl:value-of select="short_desc" /> <br /><xsl:apply-templates select="inventory[@color]"/> </li></ul> </xsl:template> <xsl:template match="inventory[@color and @location='warehouse']"> -- <xsl:value-of select="@color" /> <br/> </xsl:template>
Adding Sales Prices <xsl:template match="product"> <ul><li> <xsl:apply-templates select="product_id" /> <xsl:value-of select="short_desc" /> <br /><xsl:apply-templates select="inventory[@color]"/> <p><xsl:value-of select="price[@pricetype='sale']"/></p> </li></ul> </xsl:template> <xsl:template match="inventory[@color and @location='warehouse']"> -- <xsl:value-of select="@color" /> <br/> </xsl:template>
Using the Pipe Notation for “or” <xsl:template match="product"> <ul><li> <xsl:apply-templates select="product_id" /> <xsl:value-of select="short_desc" /> <br /><xsl:apply-templates select="inventory[@color]"/> <p><xsl:value-of select="price[@pricetype='sale'] | price[@pricetype != 'cost']"/></p> </li></ul> </xsl:template>
Looking for Descendants Instead of Children <xsl:template match="product"> <ul><li> <xsl:apply-templates select="product_id" /> <xsl:value-of select="short_desc" /> <br /><xsl:apply-templates select="inventory[@color]"/> <p><xsl:value-of select=“.//price[@pricetype='sale'] | .//price[@pricetype != 'cost']"/></p> </li></ul> </xsl:template>
Looking for Retail Prices <xsl:template match="product"> <ul><li> <xsl:apply-templates select="product_id" /> <xsl:value-of select="short_desc" /> <br /><xsl:apply-templates select="inventory[@color]"/> <p><xsl:value-of select="price[@pricetype='sale'] | price[@pricetype = ‘retail']"/></p> </li></ul> </xsl:template>
Looping <xsl:template match="/"> <xsl:for-each select="//vendor"> <h2><xsl:value-of select="vendor_name"/></h2> </xsl:for-each> <hr/> <xsl:apply-templates /> </xsl:template>
Adding Elements • <xsl:template match="/"> • <xsl:for-each select="//vendor" > • <!-- <xsl:sort select="vendor_name" /> --> • <xsl:element name="a"> • <xsl:attribute name="href"> • #<xsl:value-of select="vendor_name" /> • </xsl:attribute> • <h2><xsl:value-of select="vendor_name" /></h2> • </xsl:element> • </xsl:for-each> • <hr/> • <xsl:apply-templates /> • </xsl:template>
Conditionals • <xsl:template match="/"> • <xsl:for-each select="//vendor" > • <xsl:sort select="vendor_name" /> • <xsl:if test="@webvendor != 'no'"> • <xsl:element name="a"> • <xsl:attribute name="href"> • #<xsl:value-of select="vendor_name" /> • </xsl:attribute> • <h2><xsl:value-of select="vendor_name" /></h2> • </xsl:element> • </xsl:if> • </xsl:for-each>
Conditionals (2) • <hr/> • <!-- <xsl:apply-templates /> --> • <xsl:for-each select="//vendor" > • <xsl:sort select="vendor_name" /> • <xsl:if test="@webvendor != 'no'"> • <xsl:apply-templates /> • </xsl:if> • </xsl:for-each> • </xsl:template>
Choose • <xsl:template match="/"> • <xsl:for-each select="//vendor" > • <xsl:sort select="vendor_name" /> • <xsl:choose> • <xsl:when test="@webvendor != 'no'"> • <xsl:element name="a"> • <xsl:attribute name="href"> • #<xsl:value-of select="vendor_name" /> • </xsl:attribute> • <h2><xsl:value-of select="vendor_name" /></h2> • </xsl:element> • </xsl:when> • <xsl:otherwise> • <h2><xsl:value-of select="vendor_name" />*</h2> • </xsl:otherwise> • </xsl:choose> • </xsl:for-each>
Choose • <sup>*</sup>Products available only in showrooms. • <hr/> • <!-- <xsl:apply-templates /> --> • <xsl:for-each select="//vendor" > • <xsl:sort select="vendor_name" /> • <xsl:if test="@webvendor != 'no'"> • <xsl:apply-templates /> • </xsl:if> • </xsl:for-each> • </xsl:template>