Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 11th, 2005, 02:34 PM
Registered User
 
Join Date: Oct 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default xslt issue to translate escape sequence

This is my initial declaration
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                xmlns:math="http://www.exslt.org/math"
                                xmlns:ms ="urn:schemas-microsoft-com:xslt"
                                xmlns="abcd"
                                version="1.0">

I am getting an error at this point marked with ..
When i try to check it it says it s well formed but it s unable to recognize ms Can you help
Thanks,

..<ms:script language="VB">

    <![CDATA[
    string FormatData(String stringtoTransform)
    {
            stringtoTransform = replace(stringtoTransform,"&","&amp;")

    }
    ]]>
</ms:script>

 
Old October 13th, 2005, 01:35 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I'm not sure what the error refers to. Are you using .NET?
I don't think you can do what you want to do, escape an ampersand, this way but it's hard to tell as the forum distorts the code you sent in.

--

Joe (Microsoft MVP - XML)
 
Old October 13th, 2005, 07:37 AM
Registered User
 
Join Date: Oct 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Joe,
Thanks for responding.
What i have here is a CSV File, I am first converting it into a simple XML using XSLT.
Then using another XSLT to convert this XML into the structured XML required as end output

I am basically trying to replace & so that it can go through the XML transformation and get outputed back at the end.
However i am not sure if this works.
Here is the complete code of my XSLT
It s generic for any CSV to XML conversion. All i am trying to do is allow characters like &,'s, and , pass through this transformation. Here s my complete code.
Is there another easier way to do this?
ALso can you tell why my last element of the CSV file for every row is not getting picked up....
Thanks a ton,



-------------------------------------------------------------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                xmlns:math="http://www.exslt.org/math"
                                xmlns:ms ="urn:schemas-microsoft-com:xslt"
                                version="1.0">

<xsl:output method="html" />

 <xsl:decimal-format name="dollars" decimal-separator="." grouping-separator="," minus-sign="-" zero-digit="0" digit="#" NaN="0.00"/>

 <ms:script language="VB">
    <![CDATA[
    string FormatData(String stringtoTransform)
    {
            stringtoTransform = replace(stringtoTransform,"&","&amp;")

    }
    ]]>
</ms:script>




  <xsl:template match ="/" >
    <ROOT>
      <xsl:call-template name="texttorows" >
        <xsl:with-param name="StringToTransform" select="/ROOT" />
        <xsl:with-param name="RowNum" select="0"/>
      </xsl:call-template>
    </ROOT>
  </xsl:template>




  <xsl:template name ="texttorows" >
    <xsl:param name ="StringToTransform" select ="''" />
    <xsl:param name ="RowNum" select ="0" />

    <xsl:choose>



      <xsl:when test ="contains($StringToTransform,'#xA;')" >




            <xsl:variable name="stringlen"><xsl:value-of select="string-length(substring-before($StringToTransform,'#xA;'))"/>
            </xsl:variable>

        <xsl:if test="$stringlen > 1">
          <ROW>
            <xsl:attribute name="RowNum"><xsl:value-of select="$RowNum"/></xsl:attribute>
            <xsl:call-template name ="csvtoxml" >
              <xsl:with-param name ="StringToTransform" select ="substring-before($StringToTransform,'#xA;')" />
            </xsl:call-template>
          </ROW>
        </xsl:if>





        <xsl:call-template name ="texttorows" >
          <xsl:with-param name ="StringToTransform" >
            <xsl:value-of select ="substring-after($StringToTransform,'#xA;')" />
          </xsl:with-param>
          <xsl:with-param name ="RowNum" select="$RowNum + 1"/>
        </xsl:call-template>
      </xsl:when>




      <xsl:otherwise>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>





  <xsl:template name ="csvtoxml" >
    <xsl:param name ="StringToTransform" select ="''" />
    <xsl:param name ="FieldNum" select ="1" />

    <xsl:choose>



      <xsl:when test ="contains($StringToTransform,',')" >



        <xsl:choose>
        <xsl:when test ="$FieldNum = 1">
            <ClientId>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </ClientId>
          </xsl:when>
          <xsl:when test ="$FieldNum = 2">
            <ContractId>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </ContractId>
          </xsl:when>
          <xsl:when test ="$FieldNum = 3">
            <placementid>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementid>
          </xsl:when>
            <xsl:when test ="$FieldNum = 4">
            <accountno>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </accountno>
             </xsl:when>
           <xsl:when test ="$FieldNum = 5">
             <agencyid>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </agencyid>
            </xsl:when>
            <xsl:when test ="$FieldNum = 6">
             <agencyname>
                  <xsl:value-of select ="substring-before($StringToTransform,',')" />
             </agencyname>
              </xsl:when>
            <xsl:when test ="$FieldNum = 7">
             <locationname>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </locationname>
              </xsl:when>
                  <xsl:when test ="$FieldNum = 8">
             <officeid>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </officeid>
              </xsl:when>
                   <xsl:when test ="$FieldNum = 10">
             <clientname>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientname>
              </xsl:when>
                  <xsl:when test ="$FieldNum = 11">
             <clientremitattn>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientremitattn>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 12">
             <clientremitaddr1>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientremitaddr1>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 13">
             <clientremitaddr2>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientremitaddr2>
              </xsl:when>
                  <xsl:when test ="$FieldNum = 14">
             <clientremitcity>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientremitcity>
              </xsl:when>
               <xsl:when test ="$FieldNum = 15">
             <clientremitstate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientremitstate>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 16">
             <clientremitzipcode>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientremitzipcode>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 17">
             <clientremitphoneNo>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientremitphoneNo>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 18">
             <responsibleparty>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </responsibleparty>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 19">
             <accountholder>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </accountholder>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 20">
             <customeraddr1>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </customeraddr1>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 21">
             <customeraddr2>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </customeraddr2>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 22">
             <PTPDemandAmt>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </PTPDemandAmt>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 23">
             <customercity>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </customercity>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 24">
             <customerstate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </customerstate>

              </xsl:when>
                     <xsl:when test ="$FieldNum = 25">
             <customerzipcode>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </customerzipcode>
              </xsl:when>

                     <xsl:when test ="$FieldNum = 26">
             <createdate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </createdate>
              </xsl:when>
               <xsl:when test ="$FieldNum = 27">
             <updatedate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </updatedate>
               </xsl:when>
                  <xsl:when test ="$FieldNum = 28">
             <LastPayDate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </LastPayDate>
               </xsl:when>
                     <xsl:when test ="$FieldNum = 29">
             <completiondate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </completiondate>
              </xsl:when>
                   <xsl:when test ="$FieldNum = 30">
             <assignedamt>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </assignedamt>
              </xsl:when>
                            <xsl:when test ="$FieldNum = 34">
             <balanceamt>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </balanceamt>
              </xsl:when>

                     <xsl:when test ="$FieldNum = 38">
             <taxid>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </taxid>
            </xsl:when>
                     <xsl:when test ="$FieldNum = 39">
             <customerprimaryphoneno>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </customerprimaryphoneno>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 40">
             <officelegendfilename>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </officelegendfilename>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 41">
             <mc_visa>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </mc_visa>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 42">
             <amex>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </amex>

               </xsl:when>
                     <xsl:when test ="$FieldNum =43">
             <discover>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </discover>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 44">
             <legend>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </legend>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 45">
             <ocr>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </ocr>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 46">
             <returnbarcode>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </returnbarcode>
              </xsl:when>

                     <xsl:when test ="$FieldNum = 47">
             <ssn>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </ssn>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 48">
             <contentid>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </contentid>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 49">
             <actionid>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </actionid>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 50">
             <templatefilename>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </templatefilename>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 51">
             <ocrline>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </ocrline>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 52">
             <servicedescription>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </servicedescription>

               </xsl:when>
                      <xsl:when test ="$FieldNum = 53">
             <contactquename>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </contactquename>

              </xsl:when>
                     <xsl:when test ="$FieldNum = 55">
             <nynexaccountstatus>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </nynexaccountstatus>
              </xsl:when>

                     <xsl:when test ="$FieldNum =56">
             <nynexfillbilldate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </nynexfillbilldate>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 57">
             <nynexwriteoffdate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </nynexwriteoffdate>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 58">
             <nynexlocidentifier>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </nynexlocidentifier>

               </xsl:when>
                     <xsl:when test ="$FieldNum = 59">
             <accountnocheckdigit>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </accountnocheckdigit>
              </xsl:when>
                    <xsl:when test ="$FieldNum = 60">
             <delinquencydate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </delinquencydate>

              </xsl:when>

                     <xsl:when test ="$FieldNum = 61">
             <clientmainattn>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientmainattn>

              </xsl:when>
                     <xsl:when test ="$FieldNum = 62">
             <clientmainaddr1>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientmainaddr1>

              </xsl:when>
                     <xsl:when test ="$FieldNum = 63">
             <clientmainaddr2>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientmainaddr2>

              </xsl:when>
                     <xsl:when test ="$FieldNum = 64">
             <clientmaincity>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientmaincity>

              </xsl:when>
                     <xsl:when test ="$FieldNum = 65">
             <clientmainstate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientmainstate>
              </xsl:when>
              <xsl:when test ="$FieldNum = 66">
             <clientmainzipcode>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientmainzipcode>
            </xsl:when>

                     <xsl:when test ="$FieldNum = 67">
             <clientmainphoneno>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </clientmainphoneno>

              </xsl:when>
                     <xsl:when test ="$FieldNum = 68">
             <lastchgdate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </lastchgdate>

              </xsl:when>
                     <xsl:when test ="$FieldNum = 69">
             <terminationdate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </terminationdate>

              </xsl:when>
                     <xsl:when test ="$FieldNum = 70">
             <scheduledate>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </scheduledate>

              </xsl:when>
                          <xsl:when test ="$FieldNum = 71">
             <placementudf01>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf01>
              </xsl:when>

                                 <xsl:when test ="$FieldNum = 72">
             <placementudf02>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf02>
              </xsl:when>

                                 <xsl:when test ="$FieldNum = 73">
             <placementudf03>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf03>
              </xsl:when>

                     <xsl:when test ="$FieldNum = 74">
             <placementudf04>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf04>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 75">
             <placementudf05>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf05>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 76">
             <placementudf06>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf06>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 77">
             <placementudf07>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf07>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 78">
             <placementudf08>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf08>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 79">
             <placementudf09>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf09>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 80">
             <placementudf10>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf10>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 81">
             <placementudf11>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf11>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 82">
             <placementudf12>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf12>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 83">
             <placementudf13>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf13>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 84">
             <placementudf14>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf14>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 85">
             <placementudf15>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf15>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 86">
             <placementudf16>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf16>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 87">
             <placementudf17>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf17>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 88">
             <placementudf18>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf18>
              </xsl:when>
                     <xsl:when test ="$FieldNum = 89">
             <placementudf19>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
            </placementudf19>
              </xsl:when>
    <xsl:when test ="$FieldNum = 90">
             <placementudf20>
              <xsl:value-of select ="substring-before($StringToTransform,',')" />
               </placementudf20>
              </xsl:when>
         </xsl:choose>




        <xsl:call-template name ="csvtoxml" >
          <xsl:with-param name ="StringToTransform" >
            <xsl:value-of select ="substring-after($StringToTransform,',')" />
          </xsl:with-param>

         <xsl:with-param name ="FieldNum" select="$FieldNum + 1"/>
        </xsl:call-template>
      </xsl:when>




      <xsl:otherwise>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Template Issue saravanan.k XSLT 2 March 14th, 2007 06:41 AM
how to send escape sequence to printer ergoktas C# 0 November 28th, 2006 04:36 AM
translate() problems in XSLT 2.0 dsanders XSLT 3 February 23rd, 2006 11:14 AM
How to Escape Forward Slash in XPath/ XSLT? tclancy XSLT 4 January 10th, 2006 05:28 PM
translate xml using xslt in a batch file? hhali XSLT 3 May 8th, 2005 12:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.