XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 15th, 2011, 08:32 AM
san1646 san1646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 4 san1646 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 sec
Reputation Power: 0
Text Between Elements

Hi all,

This is my first post here...so please forgive my delinquencies.
My problem is like this:

<parent>
The member is ordered to or retained on active duty, active service, or active state service under 10
<child1/>
<child2Start/>
USC
<child2End/>
688, 12301(a), 12301(g), 12302, 12304, or 12305, or under 14
<child1/>
<child2Start/>
USC
<child2End/>
331, 332, 359, 360, 367, or 712.
</parent>


This is the input XML. Now i have to get the text between 'child2Start' and 'child2End' and put it into a new element in the target.
Since, these two are different elements, which are closing there itself, the effect is that the text between them belongs to the element 'parent'.

Please suggest any solutions for this...as i have to do it in XSL. I tried using

<xsl:for-each select="parent::node()">
<xsl:value-of select="text()[1]"/>


but could not get the exact text 'between' two elements i.e. 'child2Start' and 'child2End' .

Thank you,
Sanket

Reply With Quote
  #2  
Old June 19th, 2011, 05:15 AM
xml-profi xml-profi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 190 xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 8 m 25 sec
Reputation Power: 48
Send a message via ICQ to xml-profi
Code:
<?xml version="1.0"?>
<parent>The member is ordered to or retained on active duty, active service, or active state service under 10
	<child1/>
	<child2Start/>USC
	<child2End/>688, 12301(a), 12301(g), 12302, 12304, or 12305, or under 14
	<child1/>
	<child2Start/>USC
	<child2End/>331, 332, 359, 360, 367, or 712.</parent>


not use for-each think in template

Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="xml"/>
	<xsl:template match="/">
		<root>
			<xsl:apply-templates select="parent"/>
		</root>
	</xsl:template>
	<xsl:template match="parent">
		<!--
		<xsl:for-each select="node()">
			<xsl:if test="text()">
				<item>
					<xsl:value-of select="concat(local-name(.),'  ',.)"/>
				</item>
			</xsl:if>
		</xsl:for-each>
		-->
		<xsl:apply-templates select="text()" mode="text"/>
	</xsl:template>
	<xsl:template match="text()" mode="text">
		<!--
		<nodebefore>
			<xsl:value-of select="local-name(preceding-sibling::node()[1])"/>
		</nodebefore>
		-->
		<xsl:if test="local-name(preceding-sibling::node()[1])='child2Start' and local-name(following-sibling::node()[1])='child2End'">
			<text>
				<xsl:value-of select="normalize-space(.)"/>
			</text>
		</xsl:if>
		<!--
		<nodeafter>
			<xsl:value-of select="local-name(following-sibling::node()[1])"/>
		</nodeafter>
		-->
	</xsl:template>
</xsl:stylesheet>


result
Code:
<?xml version='1.0' ?>
<root>
  <text>USC</text>
  <text>USC</text>
</root>
__________________
Helmut Hagemann Germany

fallen to the bottom of the facts?
I reach my hand and we go together


wer lesen und google kann ist klar im Vorteil
who read and google is able is clear in the advantage

Reply With Quote
  #3  
Old June 19th, 2011, 07:59 AM
san1646 san1646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 4 san1646 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 sec
Reputation Power: 0
thanks...it worked wonders!!

Reply With Quote
  #4  
Old July 29th, 2011, 04:10 AM
san1646 san1646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 4 san1646 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 sec
Reputation Power: 0
Thanks for the solution!!!
Now, i have little extra things to be captured


<parent>
The member is ordered to or retained on active duty, active service, or active state service under 10
<child1/>
<child2Start/>
USC
<child3>
<child4>234</child4>
<child5>234</child5>
</child3>

<child6Start/>
njdsnjvndj
<child6End/>

<child2End/>
688, 12301(a), 12301(g), 12302, 12304, or 12305, or under 14
<child1/>
<child2Start/>
USC
<child2End/>
331, 332, 359, 360, 367, or 712.
</parent>


i wanna capture the elements b/w <child2Start/> <child2End/>
i.e
1.<child3>
<child4>234</child4>
<child5>234</child5>
</child3>
2.<child6Start/>
njdsnjvndj
<child6End/>

Previous solution :


inside the template <xsl:template match="text()" mode="text">,
<xsl:apply-templates select="child::*"/> will not work
as it will have only the text of current node.

Please help me in this.

Reply With Quote
  #5  
Old August 2nd, 2011, 12:34 AM
san1646 san1646 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 4 san1646 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 sec
Reputation Power: 0
a gentle reminder...
please help!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Text Between Elements

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap