Solved

Read xml text between nodes

Posted on 2010-09-23
3
776 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

679 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