Solved

Read xml text between nodes

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

760 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

22 Experts available now in Live!

Get 1:1 Help Now