#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    4
    Rep 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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    191
    Rep Power
    49
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0
    thanks...it worked wonders!!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    4
    Rep 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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0
    a gentle reminder...
    please help!!!

IMN logo majestic logo threadwatch logo seochat tools logo