[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Another newbie problem...

Subject: Re: Another newbie problem...
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Mon, 16 Jul 2001 17:47:32 -0400
item dc creator
This is one of those irritating fine points.  Your xml file has a default
namespace.  In xslt,  to match  those elements you need a prefix referring
to the element's namespace (same for attributes).  You don't have one
because (of course) you didn't use one in the source document.

The remedy is to specify one in the stylesheet.  And then you use
exclude-result-prefixes because you don't want that dummy prefix showing up
in the output.  So:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:x="http://schema.upcast.com/content"
 exclude-result-prefixes='x'>

Next, you have to make sure to specify the namespace by using your new
prefix for all elements and attributes of the source document you want to
match or select on, like so:

<xsl:template match="/x:itemListInfo">
    <html>
        <table border='1' width="100%" cellspacing="0" cellpadding="1"
class="listTable">
            <tr><xsl:apply-templates
select="x:headerInfo/x:headerList/x:header" /></tr>
            <xsl:apply-templates select="x:itemList/x:item" />
        </table>
    </html>
</xsl:template>

If you go through the entire stylesheet and add the prefix everywhere, it
will work (I tried it).  It still may have errors, but they would be normal
errors, not these mysterious namespace errors.  Note that you do NOT have to
change the source document, since those elements are properly in that
namespace already.

Cheers,

Tom P

[Kevin Nardi]

> What I'm trying to do is create a table with a row of headers first, then
> one row for each item.  However, I don't get a table at all.  It jumps
> straight into the contents of each cell.  From what I understand of XSL,
it
> should process the itemListInfo element first, then the header elements,
and
> then the item elements.  It should then process one item child element for
> each header.
>
> Can anyone help me with this?  I would very much appreciate it.
> It's probably some stupid problem that I don't know enough to understand.
>
> <itemListInfo xmlns="http://schema.upcast.com/content"
> xmlns:dc="http://purl.org/dc/elements/1.1/">
>     <checkInfo>
>         <idList/>
>     </checkInfo>
>     <headerInfo>
>         <sortBy>title</sortBy>
>         <sortOrder>ascending</sortOrder>
>         <headerList>
>             <header sort="true">
>                 <name>title</name>
>                 <title>Title</title>
>             </header>
>             <header sort="true">
>                 <name>identifier</name>
>                 <title>ID</title>
>             </header>
>             <header sort="true">
>                 <name>coverage</name>
>                 <title>Topics</title>
>             </header>
>             <header sort="true">
>                 <name>type</name>
>                 <title>Item Type</title>
>             </header>
>             <header sort="true">
>                 <name>uri</name>
>                 <title>Location</title>
>             </header>
>             <header sort="true">
>                 <name>creator</name>
>                 <title>Creator</title>
>             </header>
>             <header sort="true">
>                 <name>lastModified</name>
>                 <title>Last-Modified</title>
>             </header>
>             <header sort="true">
>                 <name>numComments</name>
>                 <title>Comments</title>
>             </header>
>         </headerList>
>     </headerInfo>
>     <itemList>
>         <item>
>             <dc:title>Item 1</dc:title>
>             <dc:identifier>atn</dc:identifier>
>             <dc:coverage>tia</dc:coverage>
>             <dc:type>BasicItem</dc:type>
>             <uri>http://10.10.9.32/DevPortal2/portal_catalog</uri>
>             <dc:creator>janette3</dc:creator>
>             <dc:date>2001-07-09 17:21:00</dc:date>
>             <comments>
>                 <num>0</num>
>             </comments>
>         </item>
>         <item>
>             <dc:title>Item 2</dc:title>
>             <dc:identifier>atnb</dc:identifier>
>             <dc:coverage>tia</dc:coverage>
>             <dc:type>BasicItem</dc:type>
>             <uri>http://10.10.9.32/DevPortal2/portal_catalog</uri>
>             <dc:creator>janette3</dc:creator>
>             <dc:date>2001-07-09 17:22:00</dc:date>
>             <comments>
>                 <num>0</num>
>             </comments>
>         </item>
>     </itemList>
> </itemListInfo>
>
> ----------------------------------------------------
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:dc="http://purl.org/dc/elements/1.1/"
> xmlns="http://www.w3.org/TR/xhtml1/strict">
>
> <xsl:output method="html" indent="yes" />
>
> <!-- DTML Variables -->
> <xsl:variable name="bUserIsAnonymous">false</xsl:variable>
> <xsl:variable name="bUserIsManager">true</xsl:variable>
> <xsl:variable name="bCheckboxes">true</xsl:variable>
> <xsl:variable name="bLinks">true</xsl:variable>
> <xsl:variable
>
name="urlThisPage">http://10.10.9.32/DevPortal2/User/kevin/tMyItems?whichVie
w=listView</xsl:variable>
> <xsl:variable name="urlPublishItem">mPublishItem?returnTo=<xsl:value-of
> select="$urlThisPage" /></xsl:variable>
> <xsl:variable name="urlImagePath">http://10.10.9.32/images</xsl:variable>
> <xsl:variable name="username">kevin</xsl:variable>
> <!-- /DTML Variables -->
>
> <xsl:template match="text()" />
>
> <xsl:template match="itemListInfo">
> <table width="100%" cellspacing="0" cellpadding="1" class="listTable">
> <tr><xsl:apply-templates select="headerInfo/headerList/header" /></tr>
> <xsl:apply-templates select="itemList/item" />
> </table>
> </xsl:template>
>
> <xsl:template match="header">
> <td class="listHeader">
> <xsl:if test="ancestor::headerInfo/sortBy = name">
> <xsl:choose>
> <xsl:when test="ancestor::headerInfo/sortOrder = 'ascending'">
> <img src="{$urlImagePath}/pointer_down.gif" />
> </xsl:when>
> <xsl:otherwise>
> <img src="{$urlImagePath}/pointer_up.gif" />
> </xsl:otherwise>
> </xsl:choose>
> </xsl:if>
> <xsl:choose>
> <xsl:when test="@sort = 'true'">
> <a href="javascript:void(0)"><xsl:value-of select="title" /></a>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="title" />
> </xsl:otherwise>
> </xsl:choose>
> </td>
> </xsl:template>
>
> <xsl:template match="item">
> <xsl:variable name="thisItem" select="." />
> <xsl:variable name="className">
> <xsl:choose>
> <xsl:when test="position() mod 2 = 0">
> myItems1
> </xsl:when>
> <xsl:otherwise>
> myItems2
> </xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <tr class="{$className}">
> <xsl:for-each select="//itemListInfo/headerInfo/headerList/header">
> <xsl:if test="name = 'title'">
> <td align="left" class="{$className}">
> <xsl:apply-templates select="$thisItem/dc:title" />
> </td>
> </xsl:if>
> <xsl:if test="name = 'creator'">
> <td align="center" class="{$className}">
> <xsl:apply-templates select="$thisItem/dc:creator" />
> </td>
> </xsl:if>
> <xsl:if test="name = 'lastModified'">
> <td align="center" class="{$className}">
> <xsl:apply-templates select="$thisItem/dc:date" />
> </td>
> </xsl:if>
> <xsl:if test="name = 'rating'">
> <td align="center" class="{$className}">
> <xsl:apply-templates select="$thisItem/rating/ave" />
> </td>
> </xsl:if>
> <xsl:if test="name = 'numComments'">
> <td align="center" class="{$className}">
> <xsl:apply-templates select="$thisItem/comments/num" />
> </td>
> </xsl:if>
> <xsl:if test="name = 'status'">
> <td align="center" class="{$className}">
> <xsl:apply-templates select="$thisItem/status" />
> </td>
> </xsl:if>
> </xsl:for-each>
> </tr>
> </xsl:template>
>
> <xsl:template match="dc:title">
> <xsl:variable name="docID"><xsl:value-of
> select="ancestor::item/dc:identifier" /></xsl:variable>
> <xsl:if test="$bCheckboxes = 'true'">
> <input class="smallCheckbox" type="checkbox" name="ids:list"
> value="{$docID}" id="cb_{$docID}">
> <xsl:for-each select="//itemListInfo/checkInfo/idList/id">
> <xsl:if test="$docID = .">
> <xsl:attribute name="checked" />
> </xsl:if>
> </xsl:for-each>
> </input>
> </xsl:if>
> <span>
> <xsl:attribute name="title">
> <xsl:value-of select="ancestor::item/dc:coverage" />
> </xsl:attribute>
> <xsl:if test="$bLinks = 'true'">
> <xsl:choose>
> <xsl:when test="ancestor::item/dc:type = 'Personal HomePage'">
> <a href="{ancestor::item/uri}">
> <xsl:value-of select="." />
> </a>
> </xsl:when>
> <xsl:otherwise>
> <a href="{$urlThisPage}" onClick="setItemLayoverCookie('{$docID}')">
> <xsl:value-of select="." />
> </a>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:if>
> </span>
> </xsl:template>
>
> <xsl:template match="dc:creator">
> <xsl:variable name="docID"><xsl:value-of
> select="ancestor::item/dc:identifier" /></xsl:variable>
> <xsl:choose>
> <xsl:when test="$bLinks = 'true'">
> <a>
> <xsl:value-of select="." />
> </a>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="." />
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> <xsl:template match="status">
> <xsl:choose>
> <xsl:when test="($bUserIsManager = 'true') or (ancestor::item/creator =
> $username)">
> <a href="javascript:void(0)"
> onClick="pop2EditItems('{ancestor::item/uri}/{$urlPublishItem}'); return
> false;">
> <xsl:value-of select="." />
> </a>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="." />
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> <xsl:template match="dc:date">
> <span class="smallText"><i><xsl:value-of select="." /></i></span>
> </xsl:template>
>
> <xsl:template match="rating/ave">
> <xsl:value-of select="format-number(.,'0.0')" />
> </xsl:template>
>
> <xsl:template match="comments/num">
> <xsl:value-of select="." />
> </xsl:template>
>
> </xsl:stylesheet>
>



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.