Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Dynamic RSS

From: "Neil Smith [MVP Digital Media]" <neil@------.--->
To: NULL
Date: 4/9/2009 10:06:00 PM
On Tue, 7 Apr 2009 22:38:01 -0700, Kass
<Kass@d...> wrote:

>Neil,
>
>I'm back.  I did my homework and looked into the publications you suggested. 
> All very informative... there is much to know!  Here are my findings.  I'm 
>going to include code again.

>rssFeed.xml code:
>
><?xml version="1.0" encoding="utf-8" ?>
><?xml-stylesheet href="getRSS.xsl" type="text/xsl"?>
><rss version="2.0" 
>xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" 
>xmlns:media="http://search.yahoo.com/mrss" 
>xmlns:admin="http://webns.net/mvcb/" 
>xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
>xmlns:content="http://purl.org/rss/1.0/modules/content/" 
>xmlns:dc="http://purl.org/dc/elements/1.1/">


So it looks like your XSL is matching text nodes (which are in no
namespace) but not the XML nodes in the rssFeed.xml, which are in all
of the above namespaces (or rather, the root node is, which is why it
doesn't match).

Supposing you now add all the xmlns:bla="bla" above to your
<xsl:stylesheet />, that should eliminate namespace issues from the
transform.

To avoid doubt, I've modified the stylesheet to add the required
namespaces. I also changed the identity template at the bottom to
match the one I suggested in the article (otherwise you *do* only get
text nodes)

Finally, I changed the output method from <xsl:output method="text" />
to <xsl:output method="xml" /> since it seems obvious you need XML
back.




<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" 
xmlns:media="http://search.yahoo.com/mrss" 
xmlns:admin="http://webns.net/mvcb/" 
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
xmlns:content="http://purl.org/rss/1.0/modules/content/" 
xmlns:dc="http://purl.org/dc/elements/1.1/" version="1.0">

<xsl:output method="xml"/>


<!-- Find and Replace Text Template  -->

<xsl:template name="ReplaceAll">
  <xsl:param name="outputString"/>
  <xsl:param name="target"/>
  <xsl:param name="replacement"/>
  <xsl:choose>
    <xsl:when test="contains($outputString,$target)">
   
      <xsl:value-of select=
        "concat(substring-before($outputString,$target),
               $replacement)"/>
      <xsl:call-template name="ReplaceAll">
        <xsl:with-param name="outputString" 
             select="substring-after($outputString,$target)"/>
        <xsl:with-param name="target" select="$target"/>
        <xsl:with-param name="replacement" 
             select="$replacement"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$outputString"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="text()">
  <xsl:call-template name="ReplaceAll">
  <xsl:with-param name="outputString" select="."/>
  <xsl:with-param name="target" select="'Thu, 02 Apr 2009 13:00:00
CST'"/>
  <xsl:with-param name="replacement" select="'Thu, 09 Apr 2009
13:00:00 CST'"/>
  </xsl:call-template>
</xsl:template>


<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>


</xsl:stylesheet>


Accompanying PHP code :


<?php

$oDOM = new DOMDocument('1.0', 'UTF-8');
$oDOM->load("rssFeed.xml");

$oXSL = new DOMDocument('1.0', 'UTF-8');
$oXSL->load('getRSS.xsl');

$oProc = new XSLTProcessor;
$oProc->importStyleSheet($oXSL);

$oResultDoc = $oProc->transformToDoc($oDOM);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>

<textarea rows="40" cols="90" wrap="virtual">
<?php print($oResultDoc->saveXML()); ?>
</textarea>

</body>
</html>




** Note you'll need to check somewhat carefully that yout text editor
is set to use UTF-8 encoding when (re-)saving the XSL and XML as you
can easily get a character set mismatch if you save as ASCII or
ISO-8859-1 (European) by mistake.


HTH
Cheers - Neil
------------------------------------------------
Digital Media MVP : 2004-2009
http://mvp.support.microsoft.com/mvpfaqs


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent