Match current domain with XPath - html

Is it anyhow possible (with newer XPath version maybe) to get following thing working:
//a/#href[not contains("DOMAIN OF THE CURRENT PAGE")]
DOMAIN OF THE CURRENT PAGЕ should work like variable, which gets the domain - something like {HTTP_HOST}.
I want to get all external links on this way.

If the domain of the current page exists as content of the current page, then, yes, you can select it and use it in an XPath predicate. Otherwise, no, there is no standard, universal variable defined in XPath for the domain of the current page.
Any given XPath hosting language or tool may have a mechanism to provide the domain of a page. For XPath 3.0, they might leverage the standard environment variable functions, fn:environment-variable and fn:available-environment-variables.
Alternatively, you could construct the XPath dynamically within the hosting language that knows the page – see How to pass variable parameter into XPath expression?.

Related

How can I add a namespace when I use XPath using $x function in Google Chrome?

I usually use $x() function on Google Chrome development console. However, when XML file has a namespace the query does not work. I could not find any way to add the namespace. I was wondering if I am missing something or is a missing feature.
I don't know if there is a way to include namespaces in the function, but it's possible to (try to) avoid them altogether by using local-name().
For example, if your element is (picked randomly for an EDGAR filing):
<edgar:companyName>Federal Bank of Boston</edgar:companyName>
This expression
$x('//*[local-name()="companyName"]')
should select it.

In sphinx jinja2 template, get the path to current document

I'm building documentation with Sphinx and rST. The docs are internationalized and deployed to paths like this:
website.tld/en/index.html
website.tld/de/index.html
Now on each page I'd like to give a link to the same page in different languages. Current language is available as the language variable, and the list of all languages is explicitly added to the html_context and, thus, also available.
What I struggle with is the relative path to each document. Say, there's a source document at ./source/somepath/docname.rst. It builds into these:
website.tld/en/somepath/docname.html
website.tld/de/somepath/docname.html
In the Jinja2 template, how do I get the "somepath/docname.html" value?
Suddenly, I've found the solution in an answer to a related question:
{{ pagename }}
For a source document at ./source/somepath/docname.rst, the value of pagename is "somepath/docname", which is quite what I need.
Here's the documentation for this variable.

Variable in MediaWiki for the current user

In MediaWiki, you can use a variable ("Magic Word") such as
{{PAGENAME}}
or
{{REVISIONDAY}}
to get specific information related to the current page being viewed. Is there a similar variable (or perhaps a different way) to get the current user who is logged in to the wiki, i.e. something like
{{USERNAME}}
context: Trying to use the #ask query in Semantic MediaWiki to narrow the list of resulting pages to show those only the user has created or edited:
{{#ask: [[Case Reflection:+]] [[Contributing User::{{USERNAME}}]]
| format=template
| template=Case Reflection Form Summary
| link=all
| sort=Last Edited
| order=DESC
| default=You have no case reflections related to this Case Study.}}
There are a bunch of extensions for that such as GetUserName, MyVariables, UserInfo. The whole concept of showing usernames is incompatible with page caching though (you need to parse the page again every time someone looks at it) so generally not a good idea.
I was just searching for the same thing, and looking to see if I could do it without extensions. It looks like there's a default feature that allows this, as long as you want it as part of writing a static version to a page, not to say "Hello, Username!" (That last case is why they have not implemented it as a standard variable, because it causes caching problems.)
Wikimedia feature request T14733 resolves with:
{{subst:REVISIONUSER}}
{{REVISIONUSER}} will dynamically show the last editor, which is usually not what you want. But if you want, for example, to make a template that includes the user's handle as part of some inserted text, this should do the job. I think in your example above,
[[Contributing User::{{subst:REVISIONUSER}}]]
(I'm not sure if Semantic Mediawiki will make you escape out the substitutions, but if it does, further instructions are at Manual:Substitution, Multilevel substitution section.)

How to filter the content of a field in a Dreamweaver Template Building block

I am working on Dreamweaver TBB in SDL Tridion 2011.
Say my component has a field "aaa" with this content.
"hi hello <bbb name='abcd_efgh_ijkl'>MRJJJJ</bbb> how are you"
I want to write a DWT TBB such that i will produce the output as
"hi hello MRJJJJ how are you".
So I want to strip out some part of the Content in a field (here field name is aaa) when I render for display purposes.
I am new to this and got stuck here.
In a DWT TBB in Tridion you should typically only retrieve values from the Component. Processing those values is not something you'd do in the DWT.
If you do need such processing, have a look at implementing a custom IFunctionSource. With that you could write something like this in your DWT:
##StripXhtml("aaa")##
So you'd implement your own StripXhtml function in an IFunctionSource class.
For a great example of such a function source, have a look at Nuno's Dreamweaver Get Extension over on SDL Tridion World.
If you are really intent on combining HTML and processing into a single TBB, you may want to consider using a template language that supports the combination better. The XSLT Mediator and the Razor Mediator are good examples of such template types.
You could extract the value of that field and place it in your template package using either a C# Fragment or a Microsoft.NET Assembly TBB. You can then manipulate the value using C#, and output the modified value using DWT by using ##NameOfModifiedValueInPackage##. The other suggestions of Function Sources or a different type of Mediator are equally valid. However, most projects require some sort of .NET TBB anyway, so this should not be much additional work.
Feels like a ResolveXHTML kind of issue.
Are you using the 'Default Finish Actions' TBB as the last TBB in your compound template? This contains a ResolveXHTML function that converts Tridion RTF field content and removes namespaces.
I wonder if you really understand what you're trying to do.
Looking at the sample you're using here, it looks like you're trying to replace some text with a dynamic variable - like a user name. However, if you do this in a Dreamweaver Template it will be executed at publish time, not at the time the page is served to a visitor on your website, resulting in the same value being displayed to EVERY visitor of the site.

Best way/practice to ensure links are going to proper location when not on root of domain?

I've been wondering this for a while now, but what is the best way to ensure that in a web app (RoR, Sinatra, PHP, anything) that when you are creating links (either generating with a method, or writing in by hand) that they go to the proper place whether you are on the root of a domain or not: http://www.example.com/ or http://www.example.com/this/is/where/the/app/is/
My thoughts are get the end-user to specify a document root somewhere in the config of your app, and use that, however I'm trying to think of a nice way to do it without the end-user having to configure anything.
Edit: By end-user, I mean the person setting up the application on a server.
Edit: I can use the beginning '/' to always get the link relative to the domain, but the problem is what if the app itself is not at the root, but some place like http://www.example.com/this/is/where/the/app/is/ so i want to say gen_link('/') and have it return /this/is/where/the/app/is/ or gen_link('/some/thing') and return /this/is/where/the/app/is/some/thing
How about trying to set the base element in the head of you html layout?
First, get the URL, eg. in a way Ilya suggests (if PHP is OK for you). After that you can use the base tag as follows:
<base href="<?= $full_site_url ?>" />
That will set the default URL for all the links and the browser will prepend it to every relative link on the page.
First of all you need to route all your urls through some kind of url re-writer function.
So you no longer do:
Foo
But instead something like:
Foo
All the web frameworks out there have a function like this. While they usually do all kinds of magic in there (to do with MVC controller paths and views and what not), at the end of the function (conceptually) they all prepend your url with a "root" (eg "/this/is/where/the/app/is/"), so as to allow you to create urls in your application that are independent of a hard-coded base path.
RoR uses a configuration directive called "relative_url_root".
Symfony (php) uses a configuration directive also called "relative_url_root".
CakePHP uses a configuration directive called "WEBROOT_DIR".
In cases where these frameworks are running on Apache, this value is often calculated dynamically (if you haven't set it explicitly). On other webservers the environment variables are often not available or are incorrect so this value cannot be determined consistently.
ilya's answer is a good one, but I think a simpler way to do this is just to precede all your links with a leading "/". This will ensure that they are always relative to the root of the domain:
Something <!-- Always links to www.domain.com/some/thing -->
Something <!-- Acutal destination depends current path -->
You can determine everything you need yourself, no need for configs.
Here’s a PHP example (let’s say index.php is your script name):
<?
$folder_on_server = substr ($_SERVER['PHP_SELF'], 0, strpos ($_SERVER['PHP_SELF'], '/index.php'));
$server_name = $_SERVER['SERVER_NAME'];
if (80 != $_SERVER['SERVER_PORT']) {
$server_name .= ':'. $_SERVER['SERVER_PORT'];
}
$full_site_url = 'http://'. $server_name . $folder_on_server;
?>
Now, you can always make a link like this:
Something
See also discussion in comments.