Solved

Read xml text between nodes

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
TripAdvisor Widgets on WordPress Websites 10 309
selectSingleNode in Access 2013 11 78
How can I write .htaccess code to redirect 301 pages? 1 141
Select distinct 25 122
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

734 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