473,406 Members | 2,620 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,406 software developers and data experts.

Changing the order of the XML

samueln12
I want to change the order the caption according to their citation present in the text.

For example:

Expand|Select|Wrap|Line Numbers
  1. <book>
  2. <chapter>
  3. <title/>
  4. <p>1 Some text goes here <xref rid="F1">Figure 1</xref></p>
  5. <p>2 Some text goes here <xref rid="F2">Figure 2</xref></p>
  6. <p>3 Some text goes here <xref rid="F4">Figure 4</xref></p>
  7. <p>3 Some text goes here <xref rid="F3">Figure 3</xref></p>
  8. <p>4 Some text goes here</p>
  9. <p>5 Some text goes here <xref rid="F5">Figure 5</xref></p>
  10. <p>6 Some text goes here <xref rid="F7">Figure 7</xref></p>
  11. <p>7 Some text goes here</p>
  12. <p></p>
  13. <floats>
  14. <figure id="F1">Figure 1. Figure one text goes here</figure>
  15. <figure id="F2">Figure 2. Figure one text goes here</figure>
  16. <figure id="F3">Figure 3. Figure one text goes here</figure>
  17. <figure id="F4">Figure 4. Figure one text goes here</figure>
  18. <figure id="F5">Figure 5. Figure one text goes here</figure>
  19. <figure id="F6">Figure 6. Figure one text goes here</figure>
  20. <figure id="F7">Figure 7. Figure one text goes here</figure>
  21. </floats>
  22. </chapter>
  23. </book>
After changing the XML should look like this:
Expand|Select|Wrap|Line Numbers
  1. <book>
  2. <chapter>
  3. <title/>
  4. <p>1 Some text goes here <xref rid="F1">Figure 1</xref>
  5. <figure id="F1">Figure 1. Figure one text goes here</figure>
  6. </p>
  7. <p>2 Some text goes here <xref rid="F2">Figure 2</xref>
  8. <figure id="F2">Figure 2. Figure one text goes here</figure>
  9. </p>
  10. <p>3 Some text goes here <xref rid="F4">Figure 4</xref></p>
  11. <p>3 Some text goes here <xref rid="F3">Figure 3</xref>
  12. <figure id="F3">Figure 3. Figure one text goes here</figure>
  13. <figure id="F4">Figure 4. Figure one text goes here</figure>
  14. </p>
  15. <p>4 Some text goes here</p>
  16. <p>5 Some text goes here <xref rid="F5">Figure 5</xref>
  17. <figure id="F5">Figure 5. Figure one text goes here</figure>
  18. </p>
  19. <p>6 Some text goes here <xref rid="F7">Figure 7</xref>
  20. <figure id="F6">Figure 6. Figure one text goes here</figure>
  21. <figure id="F7">Figure 7. Figure one text goes here</figure>
  22. </p>
  23. <p>7 Some text goes here</p>
  24. <p></p>
  25. <floats>
  26. </floats>
  27. </chapter>
  28. </book>
Please guide me how to do this

Thanks
Sam
Apr 12 '10 #1
8 1696
Dormilich
8,658 Expert Mod 8TB
which language do you want to use for that?
Apr 12 '10 #2
XSLT version=2.0
Apr 12 '10 #3
jkmyoung
2,057 Expert 2GB
?
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="xref">
  2.   <xsl:copy-of select="."/>
  3.   <xsl:copy-of select="descendant::chapter/floats/figure[@id = current/@rid]"/>
  4. </xsl:template>
  5.  
I don't understand how you know where to put
<figure id="F6">Figure 6. Figure one text goes here</figure>
Apr 12 '10 #4
@jkmyoung
That is the client requirement. If any citation missing we have to place after the preceding citation.
Apr 12 '10 #5
jkmyoung
2,057 Expert 2GB
Could you explain the figure3 and figure4 relation?

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="xref"> 
  2.   <xsl:copy-of select="."/> 
  3.   <xsl:apply-templates select="descendant::chapter/floats/figure[@id = current/@rid]"/> 
  4. </xsl:template> 
  5. <xsl:template match="floats"/> <!-- may or may not be necessary depending on your layout-->
  6. <xsl:template match="figure">
  7.     <xsl:for-each select="preceding-sibling::figure[1]">
  8.       <xsl:if test="not(//xref[@rid = current()/@id])"><!-- orphan? -->
  9.          <xsl:apply-templates select="."/>
  10.       </xsl:if>
  11.     </xsl:for-each>
  12.     <xsl:copy-of select="."/>
  13. </xsl:template>
  14.  
Apr 12 '10 #6
@jkmyoung
If citation are not in order e.g. Figure 4 first and Figure 3 next, Figure 4 should placed after figure 3, even though figure 4 citation in first.

For example, if figure 3 not cited in the text then figure 3 go under figure 2. and Figure 4 place under the Figure 4 paragraph

I hope this will help u
Apr 12 '10 #7
jkmyoung
2,057 Expert 2GB
Actually that pretty much completely screws it up.

In order to get correct order processing, you will have to process using the figures. Processing will have to be done linearly with much checking back, and with state variables, not parallel.

At this point I would recommend not using XSLT.
Apr 12 '10 #8
@jkmyoung
ok thanks i done this using perl. but i know that using XSLT its very easy.
Apr 12 '10 #9

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

Similar topics

15
by: oom | last post by:
I am a bit of a newbie when it comes to python, when working with lists today I noticed some very odd behaviour, any suggestions welcome: Python 2.2.3 (#1, Nov 6 2003, 14:12:38) on linux2...
2
by: Paolo Pignatelli | last post by:
I am trying to get an output/file like this (below) in an XML file (MyXmlFile.xml) (which I will use for a slide show) -- <gallery timer="3" order="sequential" fadetime="2" looping="yes"...
0
by: Tom | last post by:
Using AccessXP - Access2000 In my application, when an order is entered, inventory is automatically adjusted, a pull list is created, items are pulled to fill the order, and the order is...
16
by: StenKoll | last post by:
Help needed in order to create a register of stocks in a company. In accordance with local laws I need to give each individual share a number. I have accomplished this by establishing three tables...
1
by: Shawn Benson | last post by:
I have a Windows form where a user enters an order number which returns a dataset that is bound to a datagrid. The problem is when a user clicks on a cell in the datagrid, then enters another...
7
by: Dan Sikorsky | last post by:
How do you iterate thru a dataset to change money fields to a different value? Here's what I have. My dataset is filled directly from a stored procedure. ' Create Instance of Connection and...
32
by: deko | last post by:
I have a popup form with a textbox that is bound to a memo field. I've been warned about memo fields so I'm wondering if I should use this code. Is there any risk with changing the form's...
6
by: Jim Devenish | last post by:
I have 3 views, two of which depend on the other: CREATE VIEW dbo.CustomerListQueryAccounts AS SELECT dbo.CustomerListQuery.* FROM dbo.CustomerListQuery WHERE (isProspect = 0)...
4
by: Jon Slaughter | last post by:
Is there any method to temporarily disable focus changing?(I assume only method is tab or mouse?) This problem has been tieing me up for a while and nothing seems to work. The only thing that I...
5
by: marton | last post by:
Hi there, I'm new to posting on the forum, and I've been working with MS Access for a couple of years, but and other than that know nothing about programming. I have a fairly simple, networked,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.