Solved

Read xml text between nodes

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Removing Flash from Website 6 45
IndexedDB how to clear the DB when returning but not refreshing? 1 151
API Soap Calls 4 87
Swiper slider stops between pages 11 45
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now