473,387 Members | 1,486 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,387 software developers and data experts.

Relative XPath position Opties

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 2741
jkmyoung
2,057 Expert 2GB
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
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>...
1
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...
3
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...
9
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...
3
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>...
6
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...
4
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...
10
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.