Is there any way to get access to the ROOT node from within another context?
The example above is just to show my intention. Getting access to ROOT_NODE without using '../../..' since changes in xml could break that type of selector.
XSLT
<div class="column">
<xsl:for-each select="languages/server/elem">
<!-- Context is ELEM node -->
<div>
<!-- How can I get access to the ROOT_NODE ?-->
<span class="text"><xsl:value-of select="ROOT_NODE/#title"/></span>
<!-- Print ELEM text -->
<span class="text"><xsl:value-of select="current()"/></span>
</div>
</xsl:for-each>
</div>
The expression "/" selects the document node at the root of the tree containing the context node. (All trees in 1.0 are rooted at document nodes.)
In XSLT 2.0, root() selects the root of the tree containing the context node whether or not the root is a document node.
To get the root of the principal source document even when the context node is a node in a different tree, bind a global variable
<xsl:variable name="principal-root" select="/"/>
which you can refer to anywhere as $principal-root.
Oh, and as Mads Hansen points out, if by "root node" you actually mean the outermost element node, as distinct from the document node, then you would typically use "/*".
The root node is the root of the XML tree, and is the space above the document element. Since an XML document could also have comments and processing instructions as top-level nodes, it gives you the ability to select them as well.
http://www.w3.org/TR/1999/REC-xpath-19991116/#location-paths
/ selects the document root (which is always the parent of the document element)
It sounds as if you want to reference the "root element", also known as the "document element", so that you can get the value of it's #title.
You can select that with the following XPath:
/*/#title
Related
I've an XML of below format.
<book:para>
<book:page num="228"/>
<book:page num="229"/>
Other data
</book:para>
Here I want to apply-templates to immediate page nodes before the text. I'm currently using the below XSLT for doing this task. This matches only one direct page before text.
<xsl:apply-templates select="./node()[1][self::book:page]" mode="first"/>
Please let me know how can I do it for more than one page.
Thanks
I am trying to show the date a change was made in a task. To do this, I need to inherit the template of the widget "mail_thread". That template hasn't an id in its definition. This is it:
<?xml version="1.0" encoding="UTF-8"?>
<template>
<!--
mail.Widget template used to namespace the css -->
<t t-name="mail.Root">
<div class="oe_mail">
</div>
</t>
...
<span t-att-title="widget.date">
<t t-if="widget.timerelative" t-esc="widget.timerelative"/>
<t t-if="!widget.timerelative" t-raw="widget.display_date"/>
</span>
...
</template>
In my module, I need to replace the <span> tag in order to show the date.
So, how to inherit that template and replace the tag?
There are different inheritance mechanism for client side templates (web templates, defined inside a <templates> tag, "compiled" with javascript in the client when loading it) and server-side templates (usually views, must be included in the data list in the __openerp__.py file, 'compiled' when launching/upgrading the odoo server).
You extend web/widget templates templates using <t t-extend="template_name"> followed by one or more
<t t-jquery="jquery_selector" t-operation="operation"> which acts kinda like xpath, but client side and more 'powerful'.
You don't need ids, inheritance is based on the template name. (t-name directive)
Server-Side view inheritance
Client-Side template inheritance:
Template inheritance is used to alter existing templates in-place,
e.g. to add information to templates created by an other modules.
Template inheritance is performed via the t-extend directive which
takes the name of the template to alter as parameter.
The alteration is then performed with any number of t-jquery
sub-directives:
<t t-extend="base.template">
<t t-jquery="ul" t-operation="append">
<li>new element</li>
</t> </t>
The t-jquery directives takes a CSS selector. This selector is used on
the extended template to select context nodes to which the specified
t-operation is applied:
append
the node’s body is appended at the end of the context node (after the context node’s last child)
prepend
the node’s body is prepended to the context node (inserted before the context node’s first child)
before
the node’s body is inserted right before the context node
after
the node’s body is inserted right after the context node
inner
the node’s body replaces the context node’s children
replace
the node’s body is used to replace the context node itsel
No operation
if no t-operation is specified, the template body is interpreted as javascript code and executed with the context node as this
I also wanted to change the date show format in this xml file. So I copied the whole template for this default layout to my new module and only changed date in the span tag.
<?xml version="1.0" encoding="UTF-8"?>
<template>
<!-- default layout -->
<t t-name="mail.thread.message">
....
<span t-att-title="widget.date">
<!--<t t-if="widget.timerelative" t-esc="widget.timerelative"/>-->
<!--<t t-if="!widget.timerelative" t-raw="widget.display_date"/>-->
<t t-raw="widget.display_date"/>
</span>
....
</t>
</template>
need to declare this xml file in your __openerp__.py
It worked for me.
I'm trying to write some XSLT which basically should go through the following algorithm:
if child of current node is of type Accordion
if child of Accordion node is of type AccordionItem
take the AccordionItem's title and content and display in <div> tags
end if
end if
It seems pretty straight forward, but the code I currently have doesn't appear to be working as it should. I must be missing something, but I can't figure out exactly what. Here's my XSLT code so far:
<xsl:for-each select="$currentPage/ancestor-or-self::Home//AccordionItem[#isDoc]">
<div id="accordion">
<h3><a href='#'><xsl:value-of select="accordionItemTitle"/></a></h3>
<div><xsl:value-of select="accordionItemContent" disable-output-escaping="yes" />
</div>
</div>
</xsl:for-each>
Can anyone offer any suggestions as to why this wouldn't be working correctly? Thanks in advanced!
It seems that your XPath isn't quite behaving as you've defined in your algorithm and is navigating to the node of type Home, is that intended?
If not, try modifying the XPath to the following:
<xsl:for-each select="$currentPage/Accordion/AccordionItem[#isDoc]">
I would like to write Nodes like
<name>Peter</name>
(with start and end tag) into a QDomDocument.
When I create QDomElements and append them as child to a parent element:
QDomElement node = doc.createElement("node");
parent.appendChild(node);
They are added as
<node/>
to the parent element. The parent automatically gets a start and end tag so the file would look like this:
<parent>
<node/>
</parent>
But how do I add a value to my node so that it looks like I want it (with value between start and end tag). Adding a new QDomElement as child to node it would just look like . Adding attribute would show up like ?
Would be great if anyone could help me! Thanks!
Create a text node using DOM Document, and add it to your newly created element as a child:
QDomElement node = doc.createElement("name");
parent.appendChild(node);
// Now, add a text element to your node
node.appendChild( doc.createTextNode( "Peter"));
Lets say I have the following code snippet below, how do I also apply the disable-output-escaping to the {name} in the title attribute?
<a title="{name}"><xsl:value-of select="name" disable-output-escaping="yes" /></a>
This has really got me stumped.
Thanks guys.
This cannot be done with XSLT. The spec says:
It is an error for output escaping to
be disabled for a text node that is
used for something other than a text
node in the result tree.
Thus it makes no difference if you use Attribute Value Templates or xsl:attribute with xsl:value-of, because you're generating an attribute node, not a text node. It's a limitation in the language.
You can't as is. The {name} shortcut doesn't allow additional parameters. Use the <xsl:attribute> tag instead.