Forum Moderators: open
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" indent = "no" encoding="UTF-8"/>
<xsl:template match="pcc">
<xsl:text>insert into mampcpwrk (name,prcode,wrkph2,adrln1,zipcod,zipcod4,titlcd,provno,wrkph1,adrln2,citycd,stacod)values(</xsl:text>
'<xsl:value-of select="@name"/>',
'<xsl:value-of select="@cde_service_loc"/>',
'<xsl:value-of select="@num_phone"/>',
'<xsl:value-of select="@adr_mail_strt1"/>',
'<xsl:value-of select="@adr_mail_zip"/>',
'<xsl:value-of select="@adr_mail_zip_4"/>',
'<xsl:value-of select="@nam_title"/>',
'<xsl:value-of select="@id_provider"/>',
'<xsl:value-of select="@num_area_code"/>',
'<xsl:value-of select="@adr_mail_strt2"/>',
'<xsl:value-of select="@adr_mail_city"/>',
'<xsl:value-of select="@adr_mail_state"/>');
</xsl:template>
</xsl:stylesheet>
If you are able to use XSLT 2.0 [w3.org] (This is NOT the case if you use the built-in PHP 5 XSLTProcessor [us2.php.net]. If you use this, then you MUST use XSLT 1.0 [w3.org]), then you have a built-in XPath function [w3schools.com] to do this (replace()). This function is not available in XSLT 1.0. In XSLT 1.0, you have to do some real fancy footwork, doing substring-before, then substring-after, etc.
What I recommend, if you are using XSLTProcessor in PHP, is to use a PHP function callout [us2.php.net]. This is actually pretty simple, and I use it in my own work. The only drawback is that you can't debug it in something like <oXygen/> [oxygenxml.com].
here's a string replacement template that has served me well for a while
<xsl:template name="string-replace">
<xsl:param name="arg" />
<xsl:param name="toReplace" />
<xsl:param name="replaceWith" />
<xsl:choose>
<xsl:when test="contains($arg, $toReplace)">
<xsl:variable name="prefix" select="substring-before($arg, $toReplace)"/>
<xsl:variable name="postfix" select="substring($arg, string-length($prefix)+string-length($toReplace)+1)"/>
<xsl:value-of select="concat($prefix, $replaceWith)"/>
<xsl:call-template name="string-replace">
<xsl:with-param name="arg" select="$postfix"/>
<xsl:with-param name="toReplace" select="$toReplace"/>
<xsl:with-param name="replaceWith" select="$replaceWith"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$arg"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>