|
Posted by dcrackel on 02/21/07 22:50
I have 2 different fixes, one is to a PHP function to swap the chaters
as needed:
function fixXML($string){
for($i=1; $i < strlen($string);$i++) {
$subs1 = substr ($string, $i, 4);
switch ($subs1) {
case ">":
$string = substr ($string, 0, $i) . ">" . substr ($string, $i +4,
strlen($string));
break;
case "<":
$string = substr ($string, 0, $i) . "<" . substr ($string, $i +4,
strlen($string));
break;
}
}// end for
return $string;
}
<... code ..>
print fixXML($dom->saveXML());
and another way it can be done in the XSL. I thought this method was
allot messer.... and you would need to call for each charater you need
to swap out.
Snips from test.xsl
--------
<xsl:variable name="myString" select="HEADLINE" />
<xsl:variable name="myNewString">
<xsl:call-template name="SubstringReplace">
<xsl:with-param name="stringIn" select="$myString" />
<xsl:with-param name="substringIn" select="'<'"/>
<xsl:with-param name="substringOut" select="'%3C'"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat(' input: ',$myString,' output: ',
$myNewString)" />
<xsl:template name="SubstringReplace">
<xsl:param name="stringIn" />
<xsl:param name="substringIn" />
<xsl:param name="substringOut" />
<xsl:choose>
<xsl:when test="contains($stringIn,$substringIn)">
<xsl:value-of select="concat(substring-before($stringIn,
$substringIn),$substringOut)" />
<xsl:call-template name="SubstringReplace">
<xsl:with-param name="stringIn" select="substring-after($stringIn,
$substringIn)" />
<xsl:with-param name="substringIn" select="$substringIn" />
<xsl:with-param name="substringOut" select="$substringOut" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$stringIn" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
I hope this helps someone.
good luck
Navigation:
[Reply to this message]
|