473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Xpath Help

samueln12
Hi ALL,

I have a XML file in following type

Expand|Select|Wrap|Line Numbers
  1. <xml>
  2. <para type="P">Sample text 1 goes here</para>
  3. <para>Sample text 2 goes here</para>
  4. <para>Sample text 3 goes here</para>
  5. <para type="P">Sample text 4 goes here</para>
  6. <para>Sample text 5 goes here</para>
  7. <para>Sample text 6 goes here</para>
  8. <para>Sample text 7 goes here</para>
  9. <para type="P">Sample text 8 goes here</para>
  10. <para type="P">Sample text 9 goes here</para>
  11. </xml>
I want the XML in following type

Expand|Select|Wrap|Line Numbers
  1. <xml>
  2. <para type="P">Sample text 1 goes here</para>
  3.  
  4. <para type="P">
  5. <para>Sample text 2 goes here</para>
  6. <para>Sample text 3 goes here</para>
  7. Sample text 4 goes here</para>
  8.  
  9. <para type="P">
  10. <para>Sample text 5 goes here</para>
  11. <para>Sample text 6 goes here</para>
  12. <para>Sample text 7 goes here</para>
  13. Sample text 8 goes here</para>
  14. <para type="P">Sample text 9 goes here</para>
  15. </xml>
I don't know how to handle this situation. I tried using preceding-sibling and following-sibling.

Please help me out from this situation

Thanks
Sam
Sep 28 '10 #1
1 1571
jkmyoung
2,057 Expert 2GB
Modified muenchian grouping:
Expand|Select|Wrap|Line Numbers
  1. <xsl:key name="paraP" match="para" use="generate-id((following-sibling::para[@type='P'])[1])"/>
  2.  
  3. <xsl:template match="xml">
  4. <copy>
  5.   <xsl:apply-templates match="para[@type='P']"/>
  6. </copy>
  7. </xsl:template>
  8.  
  9. <xsl:template match="para">
  10.   <para type="P">
  11.     <xsl:for-each select="key('paraP', generate-id(.))[not (@type='P')]">
  12.       <xsl:copy-of select="."/>
  13.     </xsl:for-each>
  14.     <xsl:value-of select="."/>
  15.   </para>
  16. </xsl:template>
  17.  

It looks like you're using para[@type="P"] as terminators? New lines might be off a little; modify accordingly.
Sep 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jerry O | last post by:
Hi - I am stuck on what might be a simple Xpath expression, I just can't visualize the query. I have a node set that can be the child of any of three nodes. I would like to test if a node...
2
by: Richard | last post by:
Hi, I am trying to use an XmlDocument object to manipulate the default database instance node of the enterprise template library dataConfiguration section from a custom installer step: <?xml...
3
by: rnurse | last post by:
Hi All, I'm new to XML and I'm working with an XSL style sheet. In this file I've noticed the following XPath reference: <xsl:for-each select="//SomeNodeName"> .. .. ..
1
by: Showjumper | last post by:
Hi, I need some help with xpath. I am very unfamilair with XPATH. I have an xml file with the folloing structure: <Photos> <Photo> <Description>This is a photo of horse that colicked. The bowel...
4
by: Candle | last post by:
I am an XPath newbie and I trying to write a query. I have the below xml <P C="24709" O="2019307"> <E C="1" O="1" W="True"> <A C="11" V="11" /> <A C="12" V="12" /> <A C="13" V="13" /> </E>
2
by: eggie5 | last post by:
I know how to edit my page using xpath selectors in firefox, it's just like this (in the else if). However, I can't find any way to do it in IE? I just want to find all links with the...
2
by: hary | last post by:
Hello, I have a C# application that is consuming a C# WebService. I am calling a method on the WebService and it is sending me back a response which contains an XmlDocument: string soapMessage...
2
by: Amar | last post by:
I have XML Data: <REQUEST> <PARAMETERS> <PPM Name="CCCS Filed Date" value="xxxx"></PPM> </PARAMETERS> <RECORD _FiledDate="12/15/2003"></RECORD> </REQUEST>
2
by: shiznit | last post by:
In ASP i used XMLDataSource to create a small menu. For the following xml how would i get just the @nav value and create a small navigation menu like this: Menu architecture: exhibition...
2
by: hurstbp | last post by:
Hello, I want to use xpath to reference a link in a table cell based on the location of a cell containing a related string two columns to the right along the same row. To clarify: <table> ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.