Solved

Read xml text between nodes

Posted on 2010-09-23
3
780 Views
Last Modified: 2013-11-08
Hi experts

I'm writing xsl for existing xml file and I have problem with displaying node text.
What i have to do is to keep order of text values of child nodes. I explain it on following example:

I have xml file (a part)
<page nr="8">
  <page_text>
  text 1
  <br/>
  text 2
  <br/>
  <graph>
    <path>images\PN_2007_0001.PNG</path>
   <br/>
  </graph>
  text 3
  <br/>
  <graph>
    <path>images\PN_2007_0002.PNG</path>
   <br/>
  </graph>
  text 4
  </page_text>
</page nr="8">

now, I have to retain the order of values:
text 1
text 2
<....image...>
text 3
<....image...>
text 4


I wrote the following code but I cant put text properly.

<xsl:for-each select="page">
  Page <xsl:value-of select="@nr"/><br/>
 
  <xsl:for-each select="page_text/*">
    <xsl:variable name="v_node" select="name()" />
   
    <xsl:choose>
      <xsl:when test="$v_node = 'graph'">
        <img><xsl:attribute name="src"><xsl:value-of select="path"/></xsl:attribute></img>
        <br/>
      </xsl:when>
      <xsl:when test="$v_node = 'br'">
        <br/>
      </xsl:when>
    </xsl:choose>  
  </xsl:for-each>
</xsl:for-each>

The question is how to get text of "page_text" node partially to put it between images?

Can You help me solve the problem?
Thanks for all help
0
Comment
Question by:tmprog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
grepll earned 500 total points
ID: 33746822
Try this:
<xsl:for-each select="page_text/*|page_text/text()">
    <xsl:choose>
      <xsl:when test="self::graph">
        <img><xsl:attribute name="src"><xsl:value-of select="path"/></xsl:attribute></img>
        <br/>
      </xsl:when>
      <xsl:when test="self::br">
        <br/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="."/>
      </xsl:otherwise>
    </xsl:choose>  
  </xsl:for-each>

Open in new window

0
 

Author Closing Comment

by:tmprog
ID: 33747772
Great, it works

Many thanks for help
0
 
LVL 3

Expert Comment

by:grepll
ID: 33747792
You're welcome.
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question