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

Using XPath in Styler question

ptc-953926
1-Newbie

Using XPath in Styler question



<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>Adepters:



<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>



<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>I’m
creating a Styler stylesheet and would like to use XPath in generated text to
reference the content of an element whose parent’s "name"
attribute matches the "name" attribute of the current element.
For example...




<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">Assume that my document has
this structure:




<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> <toplevel>



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> <ents>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
<ent<br/>name="abc"><value>test1</value></ent>




<span<br/>style='font-size:10.0pt;font-family:"Courier New"> <ent<br/>name="def"><value>test2</value></ent>



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> </ents>



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> .



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> .



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> .



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> <para>This
is <entref name="def"/">.</para>




<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">What XPath expression can I
use in context of this <entref> element to reference the content of the
<value> element that matches the <ent> name attribute as shown
above. In other words, returns the value "test2". I've
gotten this far:




<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> /topLevel/ents/ent[@name]/value



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">But, that always returns the
first value, "test1". Somehow I need to test @name that equals
the "name" of the current tag. I’ve gotten some feedback
from the XSL list that this isn’t possible in XPath without first
creating a variable. But, I don’t see a way to do that that’s
supported in XPath 1.0 and works as an XPath expression.




<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">Any suggestions?



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">Dave







7 REPLIES 7

<br /><br />Taking your example literally: have<br />you tried - &lt;span&lt;br/&gt;style='font-size:10.0pt;font-family:"Courier New"&gt;topLevel/ents/ent[@name=’def’]/value&lt;font&lt;br/&gt;size=2 color=navy face=Arial&gt;<br /><br /><br /><br /><br /><br /><br /><br /> <br /><br /><br /><br /><br /><br /> <br /><br />From: Hintz, David L<br /> <br /><br />Sent: Tuesday, December 19, 2006<br />12:15 PM<br /><br />To: adepters@arbortext.com<br /><br />Subject: Using XPath in Styler<br />question<br /><br /><br /><br /> <br /><br /><br /><br /><br /><br /> <br /><br />&lt;font&lt;br/&gt;size=2 color=black face="Courier New"&gt;Adepters:<br /><br /><br /><br />&lt;font&lt;br/&gt;size=2 color=black face="Courier New"&gt;<br /><br /><br /><br />&lt;font&lt;br/&gt;size=2 color=black face="Courier New"&gt;I’m creating a Styler stylesheet and would<br />like to use XPath in generated text to reference the content of an element<br />whose parent’s "name" attribute matches the "name" attribute<br />of the current element. For example...<br /><br /><br /><br />&lt;font&lt;br/&gt;size=2 color=black face="Courier New"&gt;<br /><br /><br /><br />Assume that my document has this structure:<br /><br /><br /><br /><br /><br /><br /><br /> &lt;toplevel&gt;<br /><br /><br /><br /> &lt;ents&gt;<br /><br /><br /><br /><br />&lt;ent&lt;br/&gt;name="abc"&gt;&lt;value&gt;test1&lt;/value&gt;&lt;/ent&gt;<br /><br /><br /><br /><br />&lt;ent&lt;br/&gt;name="def"&gt;&lt;value&gt;test2&lt;/value&gt;&lt;/ent&gt;<br /><br /><br /><br /> &lt;/ents&gt;<br /><br /><br /><br /> .<br /><br /><br /><br /> .<br /><br /><br /><br /> .<br /><br /><br /><br /> &lt;para&gt;This is &lt;entref&lt;br/&gt;name="def"/&gt;.&lt;/para&gt;<br /><br /><br /><br /><br /><br /><br /><br />What XPath expression can I use in context of<br />this &lt;entref&gt; element to reference the content of the &lt;value&gt;<br />element that matches the &lt;ent&gt; name attribute as shown above. In<br />other words, returns the value "test2". I've gotten this far:<br /><br /><br /><br /><br /><br /><br /><br /> /topLevel/ents/ent[@name]/value<br /><br /><br /><br /><br /><br /><br /><br />But, that always returns the first value,<br />"test1". Somehow I need to test @name that equals the<br />"name" of the current tag. I’ve gotten some feedback from<br />the XSL list that this isn’t possible in XPath without first creating a<br />variable. But, I don’t see a way to do that that’s supported<br />in XPath 1.0 and works as an XPath expression.<br /><br /><br /><br /><br /><br /><br /><br />Any suggestions?<br /><br /><br /><br /><br /><br /><br /><br />Dave<br /><br /><br /><br />&lt;font&lt;br/&gt;size=2 color=purple face=Arial&gt;<br /><br /><br /><br /> <br /><br />&gt;&gt; To unsubscribe from the list, send an email to<br />listmanager@maillist.arbortext.com with the following in the body: unsubscribe<br />adepters - For additional information on the adepters list (how to subscribe or<br />unsubscribe etc), send an email to: listmanager@maillist.arbortext.com with the<br />following in the body: info Adepters - You may also go to forums.arbortext.com,<br />enter the Adepters folder and change your subscription options and<br />preferences.&gt;&gt; <br /><br /><br /><br />



Well, that might work, but I need to determine 'def'
on the fly. Or, are you suggesting it as an interesting test?














<span<br/>style='font-size:10.0pt;font-family:Tahoma;font-weight:bold'>From:<font<br/>size=2 face=Tahoma>Sent: Tuesday, December 19, 2006
12:07 PM

To: adepters@arbortext.com

Subject: RE: Using XPath in Styler
question





<span<br/>style='font-size:12.0pt'>





Taking your example literally: have
you tried - <span<br/>style='font-size:10.0pt;font-family:"Courier New">topLevel/ents/ent[@name='def']/value













From:Sent: Tuesday, December 19, 2006
12:15 PM

To: <st1:personname<br/>w:st="on">adepters@arbortext.com</st1:personname>

Subject: Using XPath in Styler
question











<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>Adepters:



<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>



<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>I'm
creating a Styler stylesheet and would like to use XPath in generated text to
reference the content of an element whose parent's "name"
attribute matches the "name" attribute of the current element.
For example...



<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">Assume that my document has
this structure:



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
<toplevel>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
<ents>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
<ent<br/>name="abc"><value>test1</value></ent>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
<ent<br/>name="def"><value>test2</value></ent>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
</ents>



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> .



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> .



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> .



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
<para>This is <entref name="def"/">.</para>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">What XPath expression can I
use in context of this <entref> element to reference the content of the
<value> element that matches the <ent> name attribute as shown
above. In other words, returns the value "test2". I've
gotten this far:



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
/topLevel/ents/ent[@name]/value



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">But, that always returns the
first value, "test1". Somehow I need to test @name that equals
the "name" of the current tag. I've gotten some feedback
from the XSL list that this isn't possible in XPath without first
creating a variable. But, I don't see a way to do that that's
supported in XPath 1.0 and works as an XPath expression.



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">Any suggestions?



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">Dave









>> To unsubscribe from the list, send an email to listmanager@maillist.arbortext.com with the
following in the body: unsubscribe adepters - For additional information on the
adepters list (how to subscribe or unsubscribe etc), send an email to: listmanager@maillist.arbortext.com with the
following in the body: info Adepters - You may also go to forums.arbortext.com,
enter the Adepters folder and change your subscription options and
preferences.>>





<span<br/>style='font-size:12.0pt'>>> To unsubscribe from the list, send an email
to listmanager@maillist.arbortext.com
with the following in the body: unsubscribe adepters - For additional
information on the adepters list (how to subscribe or unsubscribe etc), send an
email to: listmanager@maillist.arbortext.com
with the following in the body: info Adepters - You may also go to
forums.arbortext.com, enter the Adepters folder and change your subscription
options and preferences.>>





Well, I think you answered it
already. I don't think you can do it without setting avriable value
to the value of the name attribute on the entRef tag.



I just noticed the obvious, that your
xpath expression wasn't going to return anything but the first ent tag
contents.




















From:Sent: Tuesday, December 19, 2006
1:21 PM

To: adepters@arbortext.com

Subject: RE: Using XPath in Styler
question











<font<br/>size=2 color=purple face=Arial>Well, that might work, but I
need to determine 'def' on the fly. Or, are you suggesting it
as an interesting test?




<font<br/>size=2 color=purple face=Arial>











From:Sent: Tuesday, December 19, 2006
12:07 PM

To: <st1:personname<br/>w:st="on">adepters@arbortext.com</st1:personname>

Subject: RE: Using XPath in Styler
question











Taking your example literally: have
you tried - <span<br/>style='font-size:10.0pt;font-family:"Courier New">topLevel/ents/ent[@name='def']/value















From:


Sent: Tuesday, December 19, 2006
12:15 PM

To: <st1:personname<br/>w:st="on"><st1:personname w:st="on">adepters@arbortext.com</st1:personname></st1:personname>

Subject: Using XPath in Styler
question












<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>Adepters:



<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>



<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>I'm
creating a Styler stylesheet and would like to use XPath in generated text to
reference the content of an element whose parent's "name"
attribute matches the "name" attribute of the current element.
For example...



<span<br/>style='font-size:10.0pt;font-family:"Courier New";color:black'>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">Assume that my document has
this structure:



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
<toplevel>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
<ents>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
<ent<br/>name="abc"><value>test1</value></ent>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
<ent<br/>name="def"><value>test2</value></ent>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
</ents>



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> .



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> .



<span<br/>style='font-size:10.0pt;font-family:"Courier New"> .



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
<para>This is <entref name="def"/">.</para>



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">What XPath expression can I
use in context of this <entref> element to reference the content of the
<value> element that matches the <ent> name attribute as shown
above. In other words, returns the value "test2". I've
gotten this far:



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">
/topLevel/ents/ent[@name]/value



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">But, that always returns the
first value, "test1". Somehow I need to test @name that equals
the "name" of the current tag. I've gotten some feedback
from the XSL list that this isn't possible in XPath without first
creating a variable. But, I don't see a way to do that that's
supported in XPath 1.0 and works as an XPath expression.



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">Any suggestions?



<span<br/>style='font-size:10.0pt;font-family:"Courier New">



<span<br/>style='font-size:10.0pt;font-family:"Courier New">Dave









>> To unsubscribe from the list, send an email to
<st1:personname w:st="on">listmanager@maillist.arbortext.com</st1:personname>
with the following in the body: unsubscribe adepters - For additional
information on the adepters list (how to subscribe or unsubscribe etc), send an
email to: <st1:personname w:st="on">listmanager@maillist.arbortext.com</st1:personname>
with the following in the body: info Adepters - You may also go to
forums.arbortext.com, enter the Adepters folder and change your subscription
options and preferences.>>





>> To unsubscribe from the list, send an email to <st1:personname<br/>w:st="on">listmanager@maillist.arbortext.com</st1:personname>
with the following in the body: unsubscribe adepters - For additional
information on the adepters list (how to subscribe or unsubscribe etc), send an
email to: <st1:personname w:st="on">listmanager@maillist.arbortext.com</st1:personname>
with the following in the body: info Adepters - You may also go to
forums.arbortext.com, enter the Adepters folder and change your subscription
options and preferences.>>





>> To unsubscribe from the list, send an email to
listmanager@maillist.arbortext.com with the following in the body: unsubscribe
adepters - For additional information on the adepters list (how to subscribe or
unsubscribe etc), send an email to: listmanager@maillist.arbortext.com with the
following in the body: info Adepters - You may also go to forums.arbortext.com,
enter the Adepters folder and change your subscription options and
preferences.>>




From: Hintz, David L
Sent: Tuesday, 2006 December 19 11:15
To: arbortext-adepters
Subject: Using XPath in Styler question

I'm creating a Styler stylesheet and would like to use
XPath in generated text to reference the content of an
element whose parent's "name" attribute matches the "name"
attribute of the current element. For example...

Assume that my document has this structure:

<toplevel>
<ents>
<ent name="abc"><value>test1</value></ent>
<ent name="def"><value>test2</value></ent>
</ents>
.
.
.
<para>This is <entref name="def"/">.</para>

What XPath expression can I use in context of this <entref>
element to reference the content of the <value> element that
matches the <ent> name attribute as shown above. In other
words, returns the value "test2". I've gotten this far:

/topLevel/ents/ent[@name]/value

But, that always returns the first value, "test1". Somehow
I need to test @name that equals the "name" of the current tag.

I've gotten some feedback from the XSL list that this isn't
possible in XPath without first creating a variable. But, I
don't see a way to do that that's supported in XPath 1.0 and
works as an XPath expression.

--------------------------------

Unfortunately, there are some things you can't do just in XPath,
and this is one example.

XPath allows you to access elements in your document based on
almost anything about the target element(s) as long as you don't
have to know something about two elements at the same time. In
this case, you need to know the value of the name attribute on
the entRef element at the same time you're looking at the name
attribute on an ent element.

This is easy in XSL via a variable or the current() function, but
neither of these techniques are part of XPath itself, so you'll
probably need to use some EditedSource in Styler to accomplish this.

The rest of this message is somewhat advanced; if it doesn't make
complete sense, you may need to review some of the advanced Styler
techniques and/or get some help from those who have done this sort
of this before.

I'd recommend making the Add Before generated text for the entRef
element some UFE (say, _ufe:entval) whose content (using Insert
Attribute content) is the name attribute on the entRef element.

Then style _ufe:entval to be "hidden" and then provide it with
the necessary Edited Source to do what you want for your required
outputs. (This isolates your edited source to a single UFE which
is a good practice in general when feasible.)

For FOSI, you'll need to use system-func and define a simple ACL
function. The FOSI edited source for _ufe:entval would look like:

<e-i-c gi="_ufe:entval" occur="all">
<charlist inherit="1">
<indent inherit="0"/">
<suppress sup="1"/">
</charlist>
<att>
<fillval attname="get_ent_val" attloc="system-func" <br="/> fillcat="usetext" fillchar="source"/>
</att>
</e-i-c>

(I just added the att and fillval elements to the original source
that Styler produces) and the ACL would look like:

function get_ent_val(window,oid)
{
local entref_name = oid_content(oid)

local xpath_expression =
'/topLevel/ents/ent[@name=" . entref_name . "]/value'

return xpath_string(xpath_expression)
}

For, say, HTMLFile output, I recommend you start by giving
_ufe:entval some generated text using Insert -> XPath String
where the xpath expression is something close to what you want,
say "/topLevel/ents/ent[@name]/value" as you had already tried.

Then request edited source for XSL-HTML File. This will give you
XSL code that looks a bit complicated at first, but only requires
you to find the line with "/topLevel/ents/ent[@name]/value" then:

1. in that line, change "[@name]" to read "[@name=$entref_name]"

2. just before that line, add:
<xsl:variable name="entref_name" select="text()"/">

If you want XSL-FO, XSL-Web, or HTMLHelp output too, you would
do the same thing as described here for XSL-HTMLFile.

paul

Paul,

Paul,

Thank you for taking the time for the detailed response to my post. I
should have mentioned that the solution I need is only for the Arbortext
Editor view. We won't be using this Stylersheet to produce output.
That probably would have simplified your response some.

Although I do need to read up on advanced Styler techniques, I started
to implement your suggestions. I was able to follow your steps up until
"Then style _ufe:entval to be "hidden" and then provide it with
the necessary Edited Source to do what you want for your required
outputs." I'm not sure what you mean by providing the necessary Edited
Source, especially considering that I'm only interested in the Editor
view.

What I currently have in my stylersheet follows (which apparently isn't
enough to display the generated text I'm looking for). Any addition
suggestions before I dive into the documentation would be greatly
appreciated.

Dave

<element name="_ufe:entRefName" style="hidden">
<context priority="0" selector="_ufe:entRefName">
<baseproperties>
<generatedtext>
<addbefore><_sfe:BeforeOrAfterText><_gte:AttributeContent attr="name"
occur="ancestor" elem="entRef"/></addbefore>
</generatedtext>
</baseproperties>
<outputproperties output="editor">
<generatedtext>
<addbefore><_sfe:BeforeOrAfterText><_gte:AttributeContent attr="name"
occur="ancestor" elem="entRef"/></addbefore>
</generatedtext>
</outputproperties>
</context>
</element>

<element name="entRef" style="inline">
<context priority="0" selector="entRef">
<baseproperties>
<generatedtext></generatedtext>
</baseproperties>
<outputproperties output="editor">
<generatedtext>
<addbefore><_sfe:BeforeOrAfterText><_gte:ElementContent
include="contentOnly" elem="_ufe:entRefName" scope="entRef"
occur="1"/></addbefore>
</generatedtext>
</outputproperties>
</context>
</element>

outputs."I'm not sure what you mean by providing the necessary Edited
Source, especially considering that I'm only interested in the Editor

view.

FOSI source edits control Editor display.


Highlight the element in question in the list of Elements.
Select Elements / Edit Element Source / FOSI.

That opens a window into editing for specific output types "as source." You don't have the Styler interface between you and the ultimate .style code. Here is where you will need to implement Paul's recommendations for creating a usetext that will display the results of the function he also provided.


--
Paul Nagai


Announcements