Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Help on search and replace

From: "Mikael Jirhage" <mikjir@--------.-->
To: 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
R&#x4;CTT" 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="&#x4;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




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