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

How does preceding-sibling::* work?

My XSL:
Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet
  2.   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.   xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
  4.   version="1.0">
  5.  
  6.   <xsl:template match="@* | node()">
  7.     <xsl:copy>
  8.       <xsl:apply-templates select="@* | node()"/>
  9.     </xsl:copy>
  10.   </xsl:template>
  11.  
  12.   <xsl:template match="w:body">
  13.  
  14.                         <xsl:for-each select="//w:p">
  15.     <xsl:variable name="COUNTER2" select="count(preceding-sibling::*) + 1" />
  16. <xsl:message><xsl:value-of select="$COUNTER2"/> 
  17. </xsl:message>
  18.                         </xsl:for-each>
  19.   </xsl:template>
  20.  
  21. </xsl:stylesheet>
  22.  

XML:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <w:document  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  3.     <w:body>
  4.  
  5.         <w:p>
  6.         </w:p>
  7.  
  8.         <w:p>
  9.         </w:p>
  10.  
  11.         <w:p>
  12.         </w:p>
  13.  
  14.         <w:tbl>
  15.             <w:tr w:rsidR="0065563E" w:rsidTr="0065563E">
  16.                 <w:trPr>
  17.                     <w:cnfStyle w:val="100000000000"/>
  18.                 </w:trPr>
  19.                 <w:tc>
  20.                     <w:tcPr>
  21.                         <w:cnfStyle w:val="001000000000"/>
  22.                         <w:tcW w:w="2394" w:type="dxa"/>
  23.                     </w:tcPr>
  24.                     <w:p w:rsidR="0065563E" w:rsidRDefault="003A0CBE" w:rsidP="0015368C"><ADDED>1-2</ADDED>
  25.                         <w:r>
  26.                             <w:t>Header</w:t>
  27.                         </w:r>
  28.                     </w:p>
  29.                 </w:tc>
  30.                 <w:tc>
  31.                     <w:tcPr>
  32.                         <w:tcW w:w="2394" w:type="dxa"/>
  33.                     </w:tcPr>
  34.                     <w:p w:rsidR="0065563E" w:rsidRDefault="0065563E" w:rsidP="0015368C">
  35.                         <w:pPr>
  36.                             <w:cnfStyle w:val="100000000000"/>
  37.                         </w:pPr>
  38.                     </w:p>
  39.                 </w:tc>
  40.                 <w:tc>
  41.                     <w:tcPr>
  42.                         <w:tcW w:w="2394" w:type="dxa"/>
  43.                     </w:tcPr>
  44.                     <w:p w:rsidR="0065563E" w:rsidRDefault="0065563E" w:rsidP="0015368C">
  45.                         <w:pPr>
  46.                             <w:cnfStyle w:val="100000000000"/>
  47.                         </w:pPr>
  48.                     </w:p>
  49.                 </w:tc>
  50.             </w:tr>
  51.         </w:tbl>
  52.  
  53.         <w:p>
  54.  
  55.         </w:p>
  56.  
  57.         <w:p>
  58.             <w:r>
  59.                 <w:t>Image inserted</w:t>
  60.             </w:r>
  61.         </w:p>
  62.  
  63.     </w:body>
  64. </w:document>
  65.  
Why do I get this dump:

1
2
3
2
2
2
5
6
I expected it to produce 1,2,3,4... so one so forth. Why is "2" repeated 3 times?
Jan 31 '10 #1

✓ answered by jkmyoung

Sorry for bumping the thread, but
use preceding::
instead of preceding-sibling::

3 2556
Dormilich
8,658 Expert Mod 8TB
because at that position there is 3 times only one preceding sibling. (mind, you are in a "subdirectory")
Jan 31 '10 #2
Catz
3
You can create a simple <xsl:for-each select="//w:p"/> and print the counter in it. You will get 1,2,3,4.. and so on.
Feb 4 '10 #3
jkmyoung
2,057 Expert 2GB
Sorry for bumping the thread, but
use preceding::
instead of preceding-sibling::
Feb 24 '10 #4

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

Similar topics

6
by: JT | last post by:
how would i transform this number: 00000102 into 102 basically, i just want to remove all preceding zeroes, but not replace all zeroes
2
by: Sven | last post by:
Hi I have the following XML & XSLT: XML: <?xml version="1.0" encoding="utf-8"?> <Source Source="IBM"> <Detail> <UserID></UserID>
2
by: KJ | last post by:
Hello All, I'd like to know what the difference is between these 2 expressions: parent::*/preceding-sib­ling::tagname VS parent::preceding-sib­ling::tagname
0
by: ksampson | last post by:
I'm at a loss here. I need to loop through a bunch of nodes, but not nodes with repeating attribute names. I've created sample data, and it works fine with syntax like: <xsl:for-each...
3
by: Joseph | last post by:
I read a piece of code, and the code looks like the following part. CWnd is a MFC class class CFrameGrabber : public CWnd { .... }; BOOL CFrameGrabber::Create(int x, int y, CWnd...
6
by: John | last post by:
Hi I would like to convert a number to string but with a preceding zero if the number is less than 10. How can I accomplish this? Thanks Regards
2
by: Greg Collins [Microsoft MVP] | last post by:
In reviewing my web site statistics, I see that I get 404 errors (often enough to make me ask about it) when users try to click on a link to a secure external site (i.e. an https:// link). I've...
4
by: james.igoe | last post by:
What Does +IIF Do as Opposed to IIF? James Igoe http://code.comparative-advantage.com/
2
by: saengpole | last post by:
Hi all, I'm a newbie in VB2005. I have a trouble getting text from textbox and combobox.SelectedValue. The values reside on two controls are text. But they are in numeric text eg. product code...
1
by: rnakawat | last post by:
I seem to have a problem using the preceding:: on substrings of the value. I'll try to explain with an example: Let's say I had a XML that look like: <Root> <Row> <Cell Name="Street"...
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: 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:
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...

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.