[xslt] newbie question




i have been tinkering with xsltproc and the heavily ms oriented xslt 
tutorial at w3schools,

http://www.w3schools.com/xsl/xsl_choose.asp


to get the simple examples to work with xsltproc you must change the 
namespace tag, and add version="1.0", and indeed i have done a few 
simple transformations, however the xsl:if and xsl:choose are not 
working for me, i am unsure what is wrong with the xpath in the expression

<xsl:if match=".[ARTIST='Bob Dylan']">

if i read this correctly the dot means the current node in the for each, 
and the ARTIST node  should be inside the nodes returned by the 
following selector:

<xsl:for-each select="CATALOG/CD">


i am getting frustrated with the lack of practical examples on xpath , 
and yes i read http://www.w3.org/TR/xpath.html, also i have found the 
lack of explanation of URI vs. URL frustrating, please correct me if i 
am wrong, they are essentially the same thing except that a uri is not 
necessarily an absolute or relative path, it may resolve to different 
locations, they don't specify protocol like <!DOCTYPE html PUBLIC 
"-//W3C//DTD HTML 4.01 Transitionl/EN">is a uri because it could be at 
any W3C ? ah, i will keep on ....

i am planning on making a basic xml database program using libxml2, one 
small hint about  the xslt equivalent of the SQL insert into would be 
nice?  just a clue please, you don't need to provide an example, or 
perhaps i should use the c api instead of xslt?  


root@h24-70-78-59:~/ddupas# xsltproc --version
Using libxml 20400, libxslt 10000 and libexslt 100
xsltproc was compiled against libxml 20400, libxslt 10000 and libexslt 100
libxslt 10000 was compiled against libxml 20400
libexslt 100 was compiled against libxml 20400

thank you

darrell
ddupasedm@netscape.net
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
  <html>
  <body>
    <table border="2" bgcolor="yellow">
      <tr>
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="CATALOG/CD">
            
<!-- xsl:if not supported? libxml2? this is
        straight from w3schools example -->
<!--
<xsl:if match=".[ARTIST='Bob Dylan']">
<tr>
<td><xsl:value-of select="TITLE"/></td>
<td><xsl:value-of select="ARTIST"/></td>
</tr>
</xsl:if>
-->


<!-- the xpath ".[ARTIST='Bob Dylan']" is not valid?
        again, this example is taken from w3scools -->
    <!--    

<tr>
<td><xsl:value-of select="TITLE"/></td>
<xsl:choose>
<xsl:when test=".[ARTIST='Bob Dylan']">
<td bgcolor="#ff0000">
<xsl:value-of select="ARTIST"/>
</td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="ARTIST"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>

    -->


      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<CATALOG>
  <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1985</YEAR>
  </CD>
  <CD>
    <TITLE>Hide your heart</TITLE>
    <ARTIST>Bonnie Tyler</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS Records</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1988</YEAR>
  </CD>
  <CD>
    <TITLE>Unchain my heart</TITLE>
    <ARTIST>Joe Cocker</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>EMI</COMPANY>
    <PRICE>8.20</PRICE>
    <YEAR>1987</YEAR>
  </CD>
</CATALOG>   


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]