Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Help on search and replace Help on search and replaceTo: NULL Date: 6/3/2004 5:13:00 PM Hi!
I have a XML-file that I am transforming (into an other XML-file) for later
import into SQL Server with SQL XML Bulk Load. At the same time I want to
search for a letter combination and replace it with a single character. I
have read about this but I can't get it to work. Could anyone tell me what
is wrong?
Original XML-file:
<?xml version='1.0' encoding='ISO-8859-1'?>
<OrcPositions xmlns="Claes_vs_Orc_Positions">
<Portfolio portfolio_name="BASKET">
<PortfolioPositions NumberOfPositions="97">
<portfolio_position instrument_tag="3681809" description="DROT
RCTT" market="Saxess" feedcode="24541" isincode="SE0001184904"
underlying="DROT" kind="Spot" multiplier="1" volume="0" />
</PortfolioPositions>
</Portfolio>
</OrcPositions>
New XML-file:
<?xml version="1.0"?>
<xs:OrcPositions xmlns:xs="Claes_vs_Orc_Positions">
<xs:Portfolio portfolio_name="BASKET" NumberOfPositions="97"
instrument_tag="3681809" description="DROT RATT" market="Saxess"
feedcode="24541" isincode="SE0001184904" underlying="DROT" kind="Spot"
strikeprice="" expirydate="" expirytype="" multiplier="1" volume="0"/>
</xs:OrcPositions>
This is the XSL I am using:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="Claes_vs_Orc_Positions" version="1.0" >
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" />
<xsl:template match="/">
<xs:OrcPositions>
<xsl:for-each
select="xs:OrcPositions/xs:Portfolio/xs:PortfolioPositions/xs:portfolio_posi
tion">
<xs:Portfolio>
<xsl:attribute name="portfolio_name">
<xsl:value-of select="../../@portfolio_name" />
</xsl:attribute>
<xsl:attribute name="NumberOfPositions">
<xsl:value-of select="../@NumberOfPositions" />
</xsl:attribute>
<xsl:attribute name="instrument_tag">
<xsl:value-of select="@instrument_tag" />
</xsl:attribute>
<xsl:attribute name="description">
<xsl:call-template name="SEARCH-AND-REPLACE">
<xsl:with-param name="string" select="@description" />
<xsl:with-param name="search-for" select="C" />
<xsl:with-param name="replace-with" select="A" />
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="market">
<xsl:value-of select="@market" />
</xsl:attribute>
<xsl:attribute name="feedcode">
<xsl:value-of select="@feedcode" />
</xsl:attribute>
<xsl:attribute name="isincode">
<xsl:value-of select="@isincode" />
</xsl:attribute>
<xsl:attribute name="underlying">
<xsl:value-of select="@underlying" />
</xsl:attribute>
<xsl:attribute name="kind">
<xsl:value-of select="@kind" />
</xsl:attribute>
<xsl:attribute name="strikeprice">
<xsl:value-of select="@strikeprice" />
</xsl:attribute>
<xsl:attribute name="expirydate">
<xsl:value-of select="@expirydate" />
</xsl:attribute>
<xsl:attribute name="expirytype">
<xsl:value-of select="@expirytype" />
</xsl:attribute>
<xsl:attribute name="multiplier">
<xsl:value-of select="@multiplier" />
</xsl:attribute>
<xsl:attribute name="volume">
<xsl:value-of select="@volume" />
</xsl:attribute>
</xs:Portfolio>
</xsl:for-each>
</xs:OrcPositions>
</xsl:template>
<xsl:template name="SEARCH-AND-REPLACE">
<xsl:param name="string" />
<xsl:param name="search-for" />
<xsl:param name="replace-with" />
<xsl:choose>
<xsl:when test='contains($string,$search-for)'>
<xsl:value-of select="substring-before($string,$search-for)"/>
<xsl:value-of select="$replace-with"/>
<xsl:call-template name="SEARCH-AND-REPLACE">
<xsl:with-param name="string"
select="substring-after($string,$search-for)" />
<xsl:with-param name="search-for" select="$search-for" />
<xsl:with-param name="replace-with" select="$replace-with" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Thanks in advance!
Mikael Jirhage, Sweden
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
