cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Two Simple XPATH questions

Highlighted
Regular Member

Two Simple XPATH questions

<tag1>


<tag2></tag2>


</tag1>



If I'm in tag2, how do I access tag1? I tried ../tag1[1] and parent[1]



And also, how would I access the first element from an att with XPATH? For example, this didn't work:



<e-i-c gi="code" occur="all">
...
<att>


<specval attname="code[1]" attloc="#xpath" attval="1"/">
<charsubset>...</charsubset>
</att>
</e-i-c>



Tags (2)
12 REPLIES 12
Highlighted

Simple XPATH question

../tag1 would work, but I'm not certain what the {1} is attempting to
represent.


On Sat, Jun 22, 2013 at 3:02 AM, Caroline Leccese <
caroline@thecodesource.net> wrote:

> <tag1>
>
> <tag2></tag2>
>
> </tag1>
>
>
>
> If I'm in tag2, how do I access tag1? I tried ../tag1{1} and parent[1]
>
Highlighted

Simple XPATH question

Ugh, sorry... early morning, I take that back.

You simply want ".." to get <tag1>

"..\tag1" would imply the parent's first child named "tag1", which does not
exist. Likewise, "..\tag2" would get self in current context.

- keith


Highlighted

Simple XPATH question

To further qualify: "parent" is an axis, not a thing itself. So you would want to use something like this:

parent::tag1

Or, if the parent element could be something other than tag1, but you want it whatever it is, you could use

parent::*

--Clay

Sent from my iPad

On Jun 22, 2013, at 6:50 AM, "Keith Berard" <-<<a style="COLOR:" blue;=" text-decoration:=" underline&quot;=" target="_BLANK" href="mailto:-">>">mailto:->> wrote:

Ugh, sorry... early morning, I take that back.

You simply want ".." to get <tag1>

"..\tag1" would imply the parent's first child named "tag1", which does not exist. Likewise, "..\tag2" would get self in current context.

- keith


On Sat, Jun 22, 2013 at 7:44 AM, Keith Berard <-<<a style="COLOR:" blue;=" text-decoration:=" underline&quot;=" target="_BLANK" href="mailto:-">>">mailto:->> wrote:
../tag1 would work, but I'm not certain what the {1} is attempting to represent.


On Sat, Jun 22, 2013 at 3:02 AM, Caroline Leccese <caroline@thecodesource.net<<a style="COLOR:" blue;=" text-decoration:=" underline&quot;=" target="_BLANK" href="mailto:caroline@thecodesource.net">>">mailto:caroline@thecodesource.net>> wrote:

<tag1>

<tag2></tag2>

</tag1>



If I'm in tag2, how do I access tag1? I tried ../tag1{1} and parent[1]

-----End Original Message-----
Highlighted

RE: Simple XPATH question

Thanks, guys. So I don't to qualify with [1] such as parent::tagA[1], because I just want the one parent node directly above tagB.



Also, how would I access the first occurring eic from the all context via XPATH?


This didn't work:



<e-i-c gi="code" occur="all">
...
<att>


<specval attname="code[1]" attloc="#xpath" attval="1"/">
<charsubset>...</charsubset>
</att>
</e-i-c>

Highlighted

Simple XPATH question

You never need a [1] when using the "parent" axis because there is only
ever one parent node. The "ancestor" axis includes the parent node, its
parent node and so on, all that way to and including the root node.

Keep in mind that the axis determines which "direction" you're looking in
the tree from the context node. The default axis is "child", so "code[1]"
will select the first child of the context node, which would be a "code"
element, in your FOSI excerpt. If I'm reading your requirement right,
you're in one of potential several sibling "code" elements and want to get
the content of the first such element.

My first inclination would be to use the "preceding-sibling" axis, with an
XPath of "preceding-sibling::code[last()]", but that wouldn't work if
you're already in the first element, so you may want to use "../code[1]",
instead. For the former, keep in mind that cardinal positions are relative
to document order except for any "backward-looking" axis, so for
"preceding-sibling", the "last()" is actually the first one, in document
order.

-Brandon 🙂


On Sat, Jun 22, 2013 at 2:56 PM, Caroline Leccese <
caroline@thecodesource.net> wrote:

> Thanks, guys. So I don't to qualify with [1] such as parent::tagA[1],
> because I just want the one parent node directly above tagB.
>
>
>
> Also, how would I access the first occurring eic from the all context via
> XPATH?
>
> This didn't work:
>
>
>
> <e-i-c gi="code" occur="all">
> ...
> <att>
>
> <specval attname="code[1]" attloc="#xpath" attval="1"/">
> <charsubset>...</charsubset>
> </att>
> </e-i-c>
>
Highlighted

RE: Simple XPATH question

Thanks, Brandon.



So would code[last()] choose the last code element? Or is it ../code[last()]?

Highlighted

Simple XPATH question

Hi Caroline,

Since you're having trouble with XPath, you might be interested in video
recordings of Ken Holman's training

">http://www.CraneSoftwrights.**com/links/udemy-ptux-online.**htm<http: www.cranesoftwrights.com=" l...

The video is a recording of the August 2008 version of the 5-day class
(over 24 hours of instruction). It is now available online as streaming
video, complete with handouts and exercises:

You can get $25 off by using coupon code: "PTUX-Single-Sourcing-**Discount"

Several folks on this list can recommend his classes. He's not traveling as
much anymore, so it can be hard to get a class that's local to you. The
video is a nice option. I personally take his class whenever he's in town.
He's always adding information (jQuery, for example) and he's just a great
instructor. I always pick up something new whenever I have the opportunity
to see him.

Cheers,
Liz


On Sat, Jun 22, 2013 at 9:57 PM, Caroline Leccese <
caroline@thecodesource.net> wrote:

> Thanks, Brandon.
>
>
>
> So would code[last()] choose the last code element? Or is it
> ../code[last()]?
>
Highlighted

Simple XPATH question

Hi Caroline:

What exactly are you trying to do? There is probably a FOSI way to do it.

Good luck!
Suzanne Napoleon
www.FOSIexpert.com
"WYSIWYG is last-century technology!"


Highlighted

RE: Simple XPATH question

Thanks, Liz. I see there are a bunch of free videos I can check out, too!



Hi Suzanne,



I wanted to be able to access the first position (or last) eic without having to code separate first/not first eics because I was having trouble with repeating header titles. I don't think I needed the XPATH after all but I did have a problem with my floats disappearing http://portal.ptcuser.org/p/fo/st/thread=53027

Highlighted

Simple XPATH question

Using occurrence is easiest and most straightforward, so the floating issue needs to be fixed. What is being floated? Are two floatlocs really needed or would one suffice?

Be sure you know which page model is being used by adding an identifier to each page header or footer or add a region with it. Use color so it is noticeable and doesn't get left in by accident.


Highlighted

Simple XPATH question

Hi Caroline,

On further reflection, I'm thinking the problem may be that the e-i-cs are not in the correct order and are not being matched properly. If occur=all is listed first, it will always be used and other occurrences will be ignored. (This may be my least favorite thing about Styler.)

Good luck!
Suzanne


Highlighted

RE: Simple XPATH question

Thanks Suzanne. I added in a last context and now it's working fine. Sheesh!

Announcements