xsl-list
[Top] [All Lists]

Re: [xsl] RSS feed with custom additional values - how best to transform?

2009-04-24 15:59:50
At 2009-04-24 14:22 -0500, Kent Nielsen wrote:
<rss version="2.0" xmlns:customns="http://www.helpyoulist.com/customns";>
  <channel>
...
    <item>
      <title>2008 Acme Floor Sander</title>
      <guid>http://www.acmeinc.com/ACL1.html</guid>
...
Here would be my XSL file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:customns="http://www.helpyoulist.com/customns";>

You probably want to add the following to clean up your HTML:

  exclude-result-prefixes="customns"

...
<xsl:template match="item">
<xsl:if test="customns:guid='http://www.acmeinc.com/ACL1.html'"> <!--
WILL REPLACE WITH VAR LATER -->

I think that should be:

   test="guid='.....'"

... and then both items appear for me.

    <xsl:value-of select="title" /><br /> <!-- WORKS FINE! -->

That didn't work for me until I changed the xsl:if test.

    <xsl:value-of select="customns:model" />|<br /> <!-- IT'A NO LIKA! -->

No problem once I changed the xsl:if tset.

What am I missing? I've tried aliases and such to no avail.

Just getting carried away with your prefixes is all.

I hope the running example below helps.

. . . . . . . . . Ken


T:\ftemp>type kent.xml
<rss version="2.0" xmlns:customns="http://www.helpyoulist.com/customns";>
  <channel>
    <title>Daily listings for Acme Inc</title>
    <link>http://www.acmeinc.com/</link>
    <description>Daily listings for Acme Inc</description>
    <language>en-us</language>
    <copyright>Copyright 2009</copyright>
    <customns:companyName>Acme Incorporated</customns:companyName>
    <customns:address1>123 Main Street</customns:address1>
    <customns:city>Anytown</customns:city>
    <customns:state>NJ</customns:state>
    <customns:zip>12345</customns:zip>
    <customns:phone>(123) 555-1212</customns:phone>
    <customns:fax>(123) 555-1213</customns:fax>
    <customns:email>info(_at_)acmeinc(_dot_)com</customns:email>
    <item>
      <title>2008 Acme Floor Sander</title>
      <guid>http://www.acmeinc.com/ACL1.html</guid>
      <description>What a great floor sander!</description>
      <customns:listingID>ACL1</customns:listingID>
      <customns:manufacturer>Acme</customns:manufacturer>
      <customns:model>FS1</customns:model>
      <customns:year>2008</customns:year>
      <customns:serial>5207</customns:serial>
      <customns:condition>New</customns:condition>
      <customns:askingPrice>519.00</customns:askingPrice>
      <customns:contact customns:sortOrder="1">
        <customns:firstName>Raul</customns:firstName>
        <customns:lastName>Jones</customns:lastName>
        <customns:email>rjones(_at_)acmeinc(_dot_)com</customns:email>
        <customns:phone>(123) 555-1213</customns:phone>
      </customns:contact>
      <customns:contact customns:sortOrder="2">
        <customns:firstName>Brandon</customns:firstName>
        <customns:lastName>Boyd</customns:lastName>
        <customns:email>bboyd(_at_)acmeinc(_dot_)com</customns:email>
        <customns:phone>(123) 555-1214</customns:phone>
      </customns:contact>
    </item>
    <item>
      <title>2007 Acme Belt Sander</title>
      <guid>http://www.acmeinc.com/ACL2556.html</guid>
      <description>This belt sander rules!</description>
      <customns:listingID>ACL2556</customns:listingID>
      <customns:manufacturer>Acme</customns:manufacturer>
      <customns:model>BS1</customns:model>
      <customns:year>2004</customns:year>
      <customns:serial>4006</customns:serial>
      <customns:condition>Used</customns:condition>
      <customns:askingPrice>299.00</customns:askingPrice>
      <customns:contact customns:sortOrder="1">
        <customns:firstName>Brandon</customns:firstName>
        <customns:lastName>Boyd</customns:lastName>
        <customns:email>bboyd(_at_)acmeinc(_dot_)com</customns:email>
        <customns:phone>(123) 555-1214</customns:phone>
      </customns:contact>
      <customns:contact customns:sortOrder="2">
        <customns:firstName>Raul</customns:firstName>
        <customns:lastName>Jones</customns:lastName>
        <customns:email>rjones(_at_)acmeinc(_dot_)com</customns:email>
        <customns:phone>(123) 555-1213</customns:phone>
      </customns:contact>
    </item>
  </channel>
</rss>

T:\ftemp>call xslt2 kent.xml kent.xsl
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

2008 Acme Floor Sander<br>FS1|<br>

T:\ftemp>type kent.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
exclude-result-prefixes="customns"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:customns="http://www.helpyoulist.com/customns";>

<xsl:output method="html" version="4.01" />
<xsl:output doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
/>
<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />

<xsl:template match="rss/channel">
    <xsl:apply-templates select="item"/>
</xsl:template>

<xsl:template match="item">
<xsl:if test="guid='http://www.acmeinc.com/ACL1.html'"> <!--
WILL REPLACE WITH VAR LATER -->
    <xsl:value-of select="title" /><br /> <!-- WORKS FINE! -->
    <xsl:value-of select="customns:model" />|<br /> <!-- IT'A NO LIKA! -->
</xsl:if>
</xsl:template>
</xsl:stylesheet>

T:\ftemp>rem Done!



--
XSLT/XSL-FO/XQuery hands-on training - Los Angeles, USA 2009-06-08
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>