DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: "template match" woes

  1. #1
    Neal Andrews Guest

    "template match" woes

    Hi All,

    Can anyone please explain why the "template match" code below never works.
    No mater what combination of slashes I place in the query the table never
    shows.
    Yet if I use the same string like so

    <xsl:for-each
    select="APPLICATION/OBJECT[@ID='Appearances']/PROPERTIES/PROPERTY">

    and "template match" = "/" then it works ok. Also works ok from DOM using
    SelectNodes() , Could anyone please explain where I am going wrong.

    TIA
    Neal


    '---------------------------------------------------------------------------
    --------
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="APPLICATION/OBJECT[@ID='Appearances']">

    <html>
    <p><xsl:value-of select="NAME"/></p>

    <xsl:for-each select="PROPERTIES/PROPERTY">
    <tr>
    <td class="TableCell"><xsl:value-of select="NAME"/></td>
    <td class="TableCell"><xsl:value-of
    select="DESCRIPTION"/></td>
    </tr>
    </xsl:for-each>

    </html>
    '---------------------------------------------------------------------------
    --------


    </xsl:template>
    </xsl:stylesheet>

    <xsl:template match="/">

    <xsl:for-each
    select="APPLICATION/OBJECT[@ID='Appearances']/PROPERTIES/PROPERTY">

    -------XML FILE------------------------------------

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <?xml-stylesheet type="text/xsl" href="obj.xsl"?>
    <APPLICATION>
    <OBJECT ID="Appearance">

    <NAME>Appearance</NAME>
    <URL>Appearance.html</URL>

    <PROPERTIES>
    <PROPERTY ID="Appearance.BackColor" TYPE="P">
    <NAME>BackColor</NAME>
    <URL>Appearance~BackColor.html</URL>
    <DESCRIPTION>Returns/sets the BackColor for an
    element.</DESCRIPTION>
    <SHOW_MENUS>1,2,3</SHOW_MENUS>
    </PROPERTY>
    <PROPERTY .....................






  2. #2
    MartinR Guest

    Re: "template match" woes


    Hi Neal,

    in my understanding, when you use the "match" statement in the template section,
    you will need an xsl:apply-templates elsewhere in order to call up the template
    the information (see last example).

    However, your thing may work as follows:

    Hope this helps
    Martin
    ---------------------------------------
    XML CODE
    ---------------------------------------
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <?xml-stylesheet type="text/xsl" href="obj.xsl"?>
    <APPLICATION>
    <OBJECT ID="Appearance">
    <NAME>Appearance</NAME>
    <URL>Appearance.html</URL>
    <PROPERTIES>
    <PROPERTY ID="Appearance.BackColor" TYPE="P">
    <NAME>BackColor</NAME>
    <URL>Appearance~BackColor.html</URL>
    <DESCRIPTION>Returns/sets the BackColor for an
    element.</DESCRIPTION>
    <SHOW_MENUS>1,2,3</SHOW_MENUS>
    </PROPERTY>
    </PROPERTIES>
    </OBJECT>
    <OBJECT ID="NoAppearance">
    <NAME>Appearance</NAME>
    <URL>Appearance.html</URL>
    <PROPERTIES>
    <PROPERTY ID="Appearance.BackColor" TYPE="P">
    <NAME>BackColor</NAME>
    <URL>Appearance~BackColor.html</URL>
    <DESCRIPTION>Returns/sets the BackColor for an
    element.</DESCRIPTION>
    <SHOW_MENUS>1,2,3</SHOW_MENUS>
    </PROPERTY>
    </PROPERTIES>
    </OBJECT>
    </APPLICATION>

    ---------------------------------------
    XSL CODE
    ---------------------------------------
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template>
    <html>
    <xsl:for-each select='APPLICATION/OBJECT[@ID="Appearance"]'>
    <p><xsl:value-of select="NAME"/></p>
    <xsl:for-each select="PROPERTIES/PROPERTY">
    <tr>
    <td class="TableCell"><xsl:value-of select="NAME"/>:::</td>
    <td class="TableCell"><xsl:value-of select="DESCRIPTION"/></td>
    </tr>
    </xsl:for-each>
    </xsl:for-each>
    </html>
    </xsl:template>
    </xsl:stylesheet>


    --------------------
    "template-match CODE"

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="/">
    <HTML>
    <BODY>
    <TABLE>
    <xsl:for-each select="customers/customer"
    order-by="address/state; name">
    <TR>
    <xsl:apply-templates select="name" />
    <xsl:apply-templates select="address" />
    <xsl:apply-templates select="phone" />
    </TR>
    </xsl:for-each>
    </TABLE>
    </BODY>
    </HTML>
    </xsl:template>

    <xsl:template match="name">
    <TD STYLE="font-size:14pt font-family:serif">
    <xsl:apply-templates />
    </TD>
    </xsl:template>

    <xsl:template match="address">
    <TD> <xsl:apply-templates /> </TD>
    </xsl:template>

    <xsl:template match="phone">
    <TD> <xsl:apply-templates /> </TD>
    </xsl:template>

    <xsl:template match="text()"><xsl:value-of /></xsl:template>

    </xsl:stylesheet>




    "Neal Andrews" <neal@nandrews.freeserve.co.uk> wrote:
    >Hi All,
    >
    >Can anyone please explain why the "template match" code below never works.
    >No mater what combination of slashes I place in the query the table never
    >shows.
    >Yet if I use the same string like so
    >
    ><xsl:for-each
    >select="APPLICATION/OBJECT[@ID='Appearances']/PROPERTIES/PROPERTY">
    >
    >and "template match" = "/" then it works ok. Also works ok from DOM using
    >SelectNodes() , Could anyone please explain where I am going wrong.
    >
    >TIA
    >Neal
    >
    >
    >'---------------------------------------------------------------------------
    >--------
    ><xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    ><xsl:template match="APPLICATION/OBJECT[@ID='Appearances']">
    >
    ><html>
    > <p><xsl:value-of select="NAME"/></p>
    >
    > <xsl:for-each select="PROPERTIES/PROPERTY">
    > <tr>
    > <td class="TableCell"><xsl:value-of select="NAME"/></td>
    > <td class="TableCell"><xsl:value-of
    >select="DESCRIPTION"/></td>
    > </tr>
    > </xsl:for-each>
    >
    ></html>
    >'---------------------------------------------------------------------------
    >--------
    >
    >
    ></xsl:template>
    ></xsl:stylesheet>
    >
    ><xsl:template match="/">
    >
    > <xsl:for-each
    >select="APPLICATION/OBJECT[@ID='Appearances']/PROPERTIES/PROPERTY">
    >
    >-------XML FILE------------------------------------
    >
    ><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    ><?xml-stylesheet type="text/xsl" href="obj.xsl"?>
    ><APPLICATION>
    > <OBJECT ID="Appearance">
    >
    > <NAME>Appearance</NAME>
    > <URL>Appearance.html</URL>
    >
    > <PROPERTIES>
    > <PROPERTY ID="Appearance.BackColor" TYPE="P">
    > <NAME>BackColor</NAME>
    > <URL>Appearance~BackColor.html</URL>
    > <DESCRIPTION>Returns/sets the BackColor for an
    >element.</DESCRIPTION>
    > <SHOW_MENUS>1,2,3</SHOW_MENUS>
    > </PROPERTY>
    > <PROPERTY .....................
    >
    >
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center