473,732 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Relative XPath position Opties

1 New Member
Hi,

I want to convert the following XML (OpenOffice Calc file):


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <office:document-content 
  3. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
  4. xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
  5. xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
  6. xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
  7. xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
  8. xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
  9. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/ 
  10. dc/elements/1.1/" 
  11. xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
  12. xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
  13. xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation: 
  14. 1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible: 
  15. 1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
  16. xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
  17. xmlns:math="http://www.w3.org/1998/Math/MathML" 
  18. xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
  19. xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
  20. xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http:// 
  21. openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/ 
  22. calc" xmlns:dom="http://www.w3.org/2001/xml-events" 
  23. xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http:// 
  24. www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema- 
  25. instance" xmlns:rpt="http://openoffice.org/2005/report" 
  26. xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
  27. xmlns:rdfa="http://docs.oasis-open.org/opendocument/meta/rdfa#" 
  28. office:version="1.2"> 
  29.         <office:body> 
  30.                 <office:spreadsheet> 
  31.                         <table:table table:name="Sheet1" table:style-name="ta1" 
  32. table:print="false"> 
  33.                                 <table:table-column table:style-name="co1" table:number-columns- 
  34. repeated="2" table:default-cell-style-name="Default"/> 
  35.                                 <table:table-column table:style-name="co2" table:default-cell- 
  36. style-name="Default"/> 
  37.                                 <table:table-row table:style-name="ro1"> 
  38.                                         <table:table-cell office:value-type="string"> 
  39.                                                 <text:p>EN-US</text:p> 
  40.                                         </table:table-cell> 
  41.                                         <table:table-cell office:value-type="string"> 
  42.                                                 <text:p>NL-NL</text:p> 
  43.                                         </table:table-cell> 
  44.                                         <table:table-cell office:value-type="string"> 
  45.                                                 <text:p>ES-ES</text:p> 
  46.                                         </table:table-cell> 
  47.                                 </table:table-row> 
  48.                                 <table:table-row table:style-name="ro2"> 
  49.                                         <table:table-cell office:value-type="string"> 
  50.                                                 <text:p>Dog</text:p> 
  51.                                         </table:table-cell> 
  52.                                         <table:table-cell office:value-type="string"> 
  53.                                                 <text:p>Hond</text:p> 
  54.                                         </table:table-cell> 
  55.                                         <table:table-cell office:value-type="string"> 
  56.                                                 <text:p>Perro</text:p> 
  57.                                         </table:table-cell> 
  58.                                 </table:table-row> 
  59.                                 <table:table-row table:style-name="ro2"> 
  60.                                         <table:table-cell office:value-type="string"> 
  61.                                                 <text:p>Cat</text:p> 
  62.                                         </table:table-cell> 
  63.                                         <table:table-cell office:value-type="string"> 
  64.                                                 <text:p>Kat</text:p> 
  65.                                         </table:table-cell> 
  66.                                         <table:table-cell office:value-type="string"> 
  67.                                                 <text:p>Gato</text:p> 
  68.                                         </table:table-cell> 
  69.                                 </table:table-row> 
  70.                                 <table:table-row table:style-name="ro2"> 
  71.                                         <table:table-cell office:value-type="string"> 
  72.                                                 <text:p>House</text:p> 
  73.                                         </table:table-cell> 
  74.                                         <table:table-cell office:value-type="string"> 
  75.                                                 <text:p>Huis</text:p> 
  76.                                         </table:table-cell> 
  77.                                         <table:table-cell office:value-type="string"> 
  78.                                                 <text:p>Casa</text:p> 
  79.                                         </table:table-cell> 
  80.                                 </table:table-row> 
  81.                                 <table:table-row table:style-name="ro2"> 
  82.                                         <table:table-cell office:value-type="string"> 
  83.                                                 <text:p>Tree</text:p> 
  84.                                         </table:table-cell> 
  85.                                         <table:table-cell office:value-type="string"> 
  86.                                                 <text:p>Boom</text:p> 
  87.                                         </table:table-cell> 
  88.                                         <table:table-cell office:value-type="string"> 
  89.                                                 <text:p>Árbol</text:p> 
  90.                                         </table:table-cell> 
  91.                                 </table:table-row> 
  92.                                 <table:table-row table:style-name="ro2"> 
  93.                                         <table:table-cell office:value-type="string"> 
  94.                                                 <text:p>Cat &amp; Dog</text:p> 
  95.                                         </table:table-cell> 
  96.                                         <table:table-cell office:value-type="string"> 
  97.                                                 <text:p>Kat &amp; Hond</text:p> 
  98.                                         </table:table-cell> 
  99.                                         <table:table-cell office:value-type="string"> 
  100.                                                 <text:p>Gato &amp; Perro</text:p> 
  101.                                         </table:table-cell> 
  102.                                 </table:table-row> 
  103.                         </table:table> 
  104.                 </office:spreadsheet> 
  105.         </office:body> 
  106. </office:document-content>

Using this style sheet:


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ 
  3. Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" 
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  5. xmlns:xlink="http://www.w3.org/1999/xlink" 
  6. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
  7. xmlns:ooo="http://openoffice.org/2004/office" 
  8. xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
  9. xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"> 
  10.         <xsl:output indent="yes"/> 
  11.         <xsl:template match="/"> 
  12.                 <martif type="TBX"> 
  13.                         <martifHeader> 
  14.                                 <fileDesc> 
  15.                                         <sourceDesc> 
  16.                                                 <p>This TBX file was converted from an OpenOffice Calc file</p> 
  17.                                         </sourceDesc> 
  18.                                 </fileDesc> 
  19.                         </martifHeader> 
  20.                         <text> 
  21.                                 <body> 
  22.                                         <xsl:for-each select="//table:table-row[position()>1]"> 
  23.                                                 <termEntry> 
  24.                                                         <xsl:for-each select="table:table-cell"> 
  25.                                                                 <langSet xml:lang="{//table:table-row[@table:style-name='ro1']/ 
  26. table:table-cell[count(ancestor::table:table-cell/preceding-sibling::*) 
  27. +1]/text:p}"> 
  28.                                                                         <tig> 
  29.                                                                                 <term> 
  30.                                                                                         <xsl:value-of select="text:p"/> 
  31.                                                                                 </term> 
  32.                                                                         </tig> 
  33.                                                                 </langSet> 
  34.                                                         </xsl:for-each> 
  35.                                                 </termEntry> 
  36.                                         </xsl:for-each> 
  37.                                 </body> 
  38.                         </text> 
  39.                 </martif> 
  40.         </xsl:template> 
  41. </xsl:stylesheet>

The desired output is (TermBase eXchange):


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <martif xmlns:fo="http://www.w3.org/1999/XSL/Format" 
  3. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
  4. xmlns:ooo="http://openoffice.org/2004/office" 
  5. xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
  6. xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
  7. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http:// 
  8. www.w3.org/2001/XMLSchema-instance" type="TBX"> 
  9.         <martifHeader> 
  10.                 <fileDesc> 
  11.                         <sourceDesc> 
  12.                                 <p>This TBX file was converted from an OpenOffice Calc file</p> 
  13.                         </sourceDesc> 
  14.                 </fileDesc> 
  15.         </martifHeader> 
  16.         <text> 
  17.                 <body> 
  18.                         <termEntry> 
  19.                                 <langSet xml:lang="EN-US"> 
  20.                                         <tig> 
  21.                                                 <term>Dog</term> 
  22.                                         </tig> 
  23.                                 </langSet> 
  24.                                 <langSet xml:lang="NL-NL"> 
  25.                                         <tig> 
  26.                                                 <term>Hond</term> 
  27.                                         </tig> 
  28.                                 </langSet> 
  29.                                 <langSet xml:lang="ES-ES"> 
  30.                                         <tig> 
  31.                                                 <term>Perro</term> 
  32.                                         </tig> 
  33.                                 </langSet> 
  34.                         </termEntry> 
  35.                         <termEntry> 
  36.                                 <langSet xml:lang="EN-US"> 
  37.                                         <tig> 
  38.                                                 <term>Cat</term> 
  39.                                         </tig> 
  40.                                 </langSet> 
  41.                                 <langSet xml:lang="NL-NL"> 
  42.                                         <tig> 
  43.                                                 <term>Kat</term> 
  44.                                         </tig> 
  45.                                 </langSet> 
  46.                                 <langSet xml:lang="ES-ES"> 
  47.                                         <tig> 
  48.                                                 <term>Gato</term> 
  49.                                         </tig> 
  50.                                 </langSet> 
  51.                         </termEntry> 
  52.                         <termEntry> 
  53.                                 <langSet xml:lang="EN-US"> 
  54.                                         <tig> 
  55.                                                 <term>House</term> 
  56.                                         </tig> 
  57.                                 </langSet> 
  58.                                 <langSet xml:lang="NL-NL"> 
  59.                                         <tig> 
  60.                                                 <term>Huis</term> 
  61.                                         </tig> 
  62.                                 </langSet> 
  63.                                 <langSet xml:lang="ES-ES"> 
  64.                                         <tig> 
  65.                                                 <term>Casa</term> 
  66.                                         </tig> 
  67.                                 </langSet> 
  68.                         </termEntry> 
  69.                         <termEntry> 
  70.                                 <langSet xml:lang="EN-US"> 
  71.                                         <tig> 
  72.                                                 <term>Tree</term> 
  73.                                         </tig> 
  74.                                 </langSet> 
  75.                                 <langSet xml:lang="NL-NL"> 
  76.                                         <tig> 
  77.                                                 <term>Boom</term> 
  78.                                         </tig> 
  79.                                 </langSet> 
  80.                                 <langSet xml:lang="ES-ES"> 
  81.                                         <tig> 
  82.                                                 <term>Árbol</term> 
  83.                                         </tig> 
  84.                                 </langSet> 
  85.                         </termEntry> 
  86.                         <termEntry> 
  87.                                 <langSet xml:lang="EN-US"> 
  88.                                         <tig> 
  89.                                                 <term>Cat &amp; Dog</term> 
  90.                                         </tig> 
  91.                                 </langSet> 
  92.                                 <langSet xml:lang="NL-NL"> 
  93.                                         <tig> 
  94.                                                 <term>Kat &amp; Hond</term> 
  95.                                         </tig> 
  96.                                 </langSet> 
  97.                                 <langSet xml:lang="ES-ES"> 
  98.                                         <tig> 
  99.                                                 <term>Gato &amp; Perro</term> 
  100.                                         </tig> 
  101.                                 </langSet> 
  102.                         </termEntry> 
  103.                 </body> 
  104.         </text> 
  105. </martif>

I'm stuck with the Xpath expression to get the desired output for the
'xml:lang' attribute. It has to take on the value of the corresponding
(i.e. same position) 'table:table-cell' element of row 1 (i.e.
<table:table-row table:style-name="ro1">). Now it always takes the
first value (i.e. EN-US).


Thanks in advance.
Thomas
Feb 18 '09 #1
1 2770
jkmyoung
2,057 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="pos" select="position()"/>
  2. ...
  3. xml:lang="{//table:table-row[@table:style-name='ro1']/  
  4. table:table-cell[position() = $pos]}"
  5.  
You were probably missing a current() somewhere.
Feb 18 '09 #2

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

Similar topics

3
1741
by: Jamie Green | last post by:
Using MSXML3.0, with the Dom SelectionLanguage set to Xpath I am trying to query the following document <Root> <Child>Name</Child> <Child>John</Child> <Child>Smith</Child> <Child>23</Child> <Child>Name</Child> <Child>Peter</Child>
1
5364
by: Wilhelm Kutting | last post by:
Hi i like to make a complex layout with css. All the content is inside a container div. I like to get the following sequence without the css-layout: logo title mainnav content i can only get the results when i use negative positioning.
3
19780
by: Markus Ernst | last post by:
Hello Reading the follwing document: http://www.w3.org/TR/WD-positioning-970131#In-flow it seems very clear that position:relative should be relative to the parent element. So in the following test case element1 and element2 should be placed side by side inside a centered white container element: http://www.markusernst.ch/test.htm
9
2155
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they should work. Also the second nav.OuterXml appears to also be wrong to me. Can someone explain to me why this does not work? (This is an example from a program we have where xpath can be entered in two parts so we have to be able
3
6806
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
6
6081
by: Gérard Talbot | last post by:
Hello fellow stylers, When trying this page http://www.gtalbot.org/BrowserBugsSection/PercentualRelativePositioning.html I get different rendered layouts with IE 6, IE 7 beta 2, Firefox 1.5.0.2 and Opera 9.0 build 8367. Firefox 1.5 and Opera 9 will just ignore the CSS declaration
4
4066
by: dropdeadster | last post by:
Trying to line up a tic-tac-toe board type grid of images using style= tags to <img inside a table TD but it's not working, I get more like a set of steps, can I get an explanation of what's wrong with this and how to do it correctly?: <table border="1"> <tr> <td valign="top" align="left">
10
3273
by: Mark | last post by:
According to my book on CSS, if you apply 'position: relative' to a block-level element, it will stay exactly where it is. However, you can then use top, left etc. to offset the element relative to its position. However, looking at other people's stylesheets, I often see 'position: relative' applied to elements but without the use of top, left etc., which makes me think using 'position: relative' has some other effect that my book has...
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9307
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.