Reading XML file via XSL

Discussion in 'XML' started by shailesh_gaikar@indiatimes.com, Jan 26, 2005.

  1. Guest

    All,

    Please help in the following.

    I am new to XML and XSL.

    I have written one XSL as follows:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:USOURCE="USOURCE.DICT">
    <xsl:template match="UNIFACE/TABLE/OCC[USOURCE:UTEXT]">
    <html>
    <h2>Y_WRITE</h2>
    <xsl:value-of select="USOURCE:UTEXT" />
    </html>
    </xsl:template></xsl:stylesheet>

    This is to extract UTEXT element contents from one xml file. But these
    contents consist of multiple lines. When I run the xml using the above
    XSL, multiple lines on in USOURCE:UTEXT get printed on single line.
    That is, all the newlines get removed.
    Is there any way in which I can preserve the newlines in the text of
    XML element and give the same output?
     
    , Jan 26, 2005
    #1
    1. Advertising

  2. wrote:


    > I am new to XML and XSL.
    >
    > I have written one XSL as follows:
    > <?xml version="1.0" encoding="ISO-8859-1"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > xmlns:USOURCE="USOURCE.DICT">
    > <xsl:template match="UNIFACE/TABLE/OCC[USOURCE:UTEXT]">
    > <html>
    > <h2>Y_WRITE</h2>
    > <xsl:value-of select="USOURCE:UTEXT" />
    > </html>
    > </xsl:template></xsl:stylesheet>
    >
    > This is to extract UTEXT element contents from one xml file. But these
    > contents consist of multiple lines. When I run the xml using the above
    > XSL, multiple lines on in USOURCE:UTEXT get printed on single line.
    > That is, all the newlines get removed.
    > Is there any way in which I can preserve the newlines in the text of
    > XML element and give the same output?


    Sounds more like a HTML problem to me, in HTML there is the <pre>
    element so you might want to use <pre> to wrap the content you have e.g.

    <xsl:template match="/">
    <html>
    <head>
    <title>some title</title>
    </head>
    <body>
    <xsl:apply-templates />
    </body>
    </html>
    </xsl:template>

    <xsl:template match="USOURCE:UTEXT">
    <pre><xsl:value-of select="." /></pre>
    </xsl:template>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 26, 2005
    #2
    1. Advertising

  3. Guest

    Thank a lot Martin.
    That solved my problem.
    Any pointers the following?
    Instead of displaying HTML output, I want to capture the output in a
    text file. Is it possible?
    Thanks again

    Shailesh
     
    , Jan 26, 2005
    #3
  4. wrote:


    > Instead of displaying HTML output, I want to capture the output in a
    > text file. Is it possible?


    Well if you are using an XSLT processor from the command line then you
    probably only need to do
    processor file.xml file.xsl > output.txt
    or similar depending on the syntax that command line shell wants.
    I don't know which XSLT processor you use, you might want to check its
    documentation for details.
    And if you need text output instead of HTML output then you need
    <xsl:eek:utput method="text" />
    in the stylesheet.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 26, 2005
    #4
  5. Guest

    I tried using
    <xsl:eek:utput method="text" />
    But the output opens in browser only.
    Also, the same original problem, 'Output on one line', comes. Here I
    cannot use <pre>.
    Any solution?
    Sorry for the trouble.
    Thanks in advance

    Shailesh
     
    , Jan 26, 2005
    #5
  6. wrote:

    > I tried using
    > <xsl:eek:utput method="text" />
    > But the output opens in browser only.


    Well if you use the browser's XSLT processor then of course it renders
    into the browser.
    If you want to create a file then you need use a processor you can run
    from the command line or using an API in a programming language of your
    choice.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 27, 2005
    #6
  7. Guest

    Thanks a lot for your guidance.
    Any good translator, which I can download for this purpose?



    wrote:
    > I tried using
    > <xsl:eek:utput method="text" />
    > But the output opens in browser only.
    > Also, the same original problem, 'Output on one line', comes. Here I
    > cannot use <pre>.
    > Any solution?
    > Sorry for the trouble.
    > Thanks in advance
    >
    > Shailesh
     
    , Jan 27, 2005
    #7
    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. Gadrin77
    Replies:
    3
    Views:
    434
    Gadrin77
    May 7, 2004
  2. Replies:
    1
    Views:
    3,610
    A. Bolmarcich
    May 27, 2005
  3. bouton
    Replies:
    0
    Views:
    405
    bouton
    Sep 22, 2005
  4. skopeko

    XML to CSV via XSL

    skopeko, Jun 20, 2008, in forum: XML
    Replies:
    1
    Views:
    701
    skopeko
    Jun 20, 2008
  5. Stefan Schulze Frielinghaus

    Display raw XML file in HTML file via XSL

    Stefan Schulze Frielinghaus, Jun 25, 2008, in forum: XML
    Replies:
    2
    Views:
    2,948
    Stefan Schulze Frielinghaus
    Jun 29, 2008
Loading...

Share This Page