xslt parsing xml data with '<' invalid character

Discussion in 'Software' started by h_q, Jan 3, 2008.

  1. h_q

    h_q Guest

    I'm using an XSLT transform to output the element value contents from a simple XML file into a new .TXT file. Everything works fine except for certain XML files, when calling msxsl with the .xslt, I get the following error:

    Code: 0xc00ce504
    File: ......
    Line: ...
    Column: ...
    A name was started with an invalid character.

    The error refers to the '<' found in the string "<20" from my example xml file below (a).

    Questions:
    (1) Will a docbase/entity solution within my xslt script avoid the "invalid character" error while retaining the '<' in the output .TXT file?
    (2) If so, could a forum member modify my example xslt script (b) with the required code?
    (3) If neither of the above will work, does someone know how to code a .bat replace of '"<' with '"&lt' (I manually did this replacement and the msxsl call works fine but I'd like to automate this in .bat)?

    Below is my project summary:

    I have a very basic xml file with the sole element value containing a lot of text data (subset example for <TEST> values):

    (a)
    <?xml version="1.0"?>
    <TEST>
    "abcdefgh", "1"
    "abcdefgh", "1"
    "abcdefgh", "1"
    "abcdefgh", "1"

    "zzzzzz","yyyyy","xxxx","<20"
    "zzzzzz","yyyyy","xxxx","40"
    "zzzzzz","yyyyy","xxxx","<20"
    </TEST>

    Below is the xslt I'm using to create a .txt file from the <TEST> value:
    (note that I'm actually using some xpath function for another purpose but to be relevant to my questions above I added <xsl:value-of select="."> to the example below)

    (b)
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="text" encoding="US-ASCII"/>
    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="TEST">
    <xsl:copy-of select="@*"/>
    <xsl:value-of select="."></xsl:value-of>
    <xsl:apply-templates select="*"/>
    </xsl:template>
    </xsl:stylesheet>

    Below is the batch script that calls msxsl:

    (c)
    ------begin .bat-----
    for /D %%k in ( C:\test\z\* ) do call :build %%~nk

    :build
    set _dr=%1
    for %%y in ( C:\test\z\*.xml ) do call :build2 %%y

    goto :eof

    :build2
    set _file2=%~pnx1
    set _outputtxt=%~pn1.txt
    msxsl %_file2% TEST.xslt -o %_outputtxt%

    :eof
    ------end .bat-----

    Thanks,
    h_q
    h_q, Jan 3, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cameron

    XSLT programming

    cameron, Jan 4, 2004, in forum: Firefox
    Replies:
    0
    Views:
    487
    cameron
    Jan 4, 2004
  2. Hank Sniadoch

    Hank Sniadoch, Aug 20, 2004, in forum: Computer Information
    Replies:
    1
    Views:
    473
    Wizard
    Aug 20, 2004
  3. kanjali

    C# condition for xml Parsing

    kanjali, Mar 28, 2008, in forum: Software
    Replies:
    0
    Views:
    866
    kanjali
    Mar 28, 2008
  4. Replies:
    1
    Views:
    4,711
  5. scorpiom

    xml and xslt

    scorpiom, Apr 20, 2012, in forum: Software
    Replies:
    0
    Views:
    830
    scorpiom
    Apr 20, 2012
Loading...

Share This Page