XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

26
XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong

Transcript of XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

Page 1: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

XSL-2

COSC643

Internet Supply-Chain Management

Sungchul Hong

Page 2: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

Last Class

• DTD

• XSL– Template– <xsl:value-of– <xsl:apply-templates>

Page 3: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

Today

• More XSL– List elements

Page 4: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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>

Page 5: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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>

Page 6: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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

Page 7: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.
Page 8: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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

Page 9: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.
Page 10: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

Displaying Attributes<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>

Page 11: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.
Page 12: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

Checking for a Specific Attribute Values

• <xsl:template match=“inventory[@color and @location=‘warehouse’]”>

Page 13: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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

Page 14: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.
Page 15: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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

Adding Sales Prices

Page 16: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.
Page 17: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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

Using the Pipe Notation for “or”

Page 18: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.
Page 19: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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>

Page 20: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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>

Page 21: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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>

Page 22: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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>

Page 23: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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

Page 24: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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>

Page 25: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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>

Page 26: XSL-2 COSC643 Internet Supply-Chain Management Sungchul Hong.

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>