Negative decimal value formatting in Altova Style Vision - xpath

I have a problem with value formatting in Altova StyleVision. Altova forums seem to be dead. Maybe someone encountered similar problem.
I have created an Auto Calculation inside XBRL table generated by StyleVision. It contains " sum( xbrli:xbrl/n1:Wages ) " xpath expression. This expression gives me a negative value. I want to format it so that it's surrounded by parentheses instead of leading minus.
I have tried using prefixes ans suffixes in "value formatting", like this (###,##0.##) or this [###,##0.##] . But I still get minus instead of parentheses. Is there a way to get around this? Any of those prefixes seem not to work for me at all.
http://manual.altova.com/Stylevision/stylevisionbasic/index.html?svpres_inputformatting.htm

Ok. It seems that problem is solved.
Created ch.xsl file with following contents:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:decimal-format name='ch' grouping-separator=" " decimal-separator=","/>
</xsl:stylesheet>
In Altova StyleVision under Design Overview -> Add new XSLT file. Choose ch.xsl.
Afterwards in Auto Calculation xpath used following expression:
format-number(sum( xbrli:xbrl/n1:Wages ),'### ##0,##;(### ##0,##)','ch')
Maybe there is a better way to do this, but it worked for me. Hope it will help someone

Related

KeyMatch not working

I have inherited a GSA installation (with no handover notes or instructions, just the manuals). I am trying to enable some features on the test appliance. I have setup some KeyMatch "ExactMatch" items, but when I search for the trigger terms the KeyMatch results do not appear.
I changed the show_keymatch to "1" in the XSLT and saved it (it was set to "0"). Here is that section of the XSLT as it appears now:
<!-- *** keymatch suggestions *** -->
<xsl:variable name="show_keymatch">1</xsl:variable>
<xsl:variable name="keymatch_text">KeyMatch</xsl:variable>
<xsl:variable name="keymatch_text_color">#2255aa</xsl:variable>
<xsl:variable name="keymatch_bg_color">#e8e8ff</xsl:variable>
Is there another area in the XSLT file, or in the admin interface, that I need to look at in order to enable keymatch?
I feel that I have followed all the instructions in the docs, but the lack of results tell me that I've missed something!
Any advice greatly appreciated.
It is always possible that the previous developer modified the XSLT and took out the code to display it or your search URL may not be using those keymatches.
Two things:
1) I recommend to create a new Front End and put your keymatches in there and test with that Front End.
2) In your search URL are proxystylesheet and client the same values? If not, make sure they are the same and pointing to the Front End that contains the keymatch entries.

Find HTML Tags in Properties

My current issue is to find HTML-Tags inside of property values. I thought it would be easy to search with a query like /jcr:root/content/xgermany//*[jcr:contains(., '<strong>')] order by #jcr:score
It looks like there is a problem with the chars < and > because this query finds everything which has strong in it's property. It finds <strong>Some Text</strong> but also This is a strong man.
Also the Query Builder API didn't helped me.
Is there a possibility to solve it with a XPath or SQL Query or do I have to iterate through the whole content?
I don't fully understand why it finds This is a strong man as a result for '<strong>', but it sounds like the unexpected behavior comes from the "simple search-engine syntax" for the second argument to jcr:contains(). Apparently the < > are just being ignored as "meaningless" punctuation.
You could try quoting the search term:
/jcr:root/content/xgermany//*[jcr:contains(., '"<strong>"')]
though you may have to tweak that if your whole XPath expression is enclosed in double quotes.
Of course this will not be very robust even if it works, since you're trying to find HTML elements by searching for fixed strings, instead of actually parsing the HTML.
If you have an specific jcr:primaryType and the targeted properties you can do something like this
select * from nt:unstructured where text like '%<strong>%'
I tested it , but you need to know the properties you are intererested in.
This is jcr-sql syntax
Start using predicates like a champ this way all of this will make sense to you!
HTML Encode <strong>
HTML Decimal <strong>
Query builder is your friend:
Predicates: (like a CHAMP!)
path=/content/geometrixx
type=nt:unstructured
property=text
property.operation=like
property.value=%<strong>%
Have go here:
http://localhost:4502/libs/cq/search/content/querydebug.html?charset=UTF-8&query=path%3D%2Fcontent%2Fgeometrixx%0D%0Atype%3Dnt%3Aunstructured%0D%0Aproperty%3Dtext%0D%0Aproperty.operation%3Dlike%0D%0Aproperty.value%3D%25%3Cstrong%3E%25
Predicates: (like a CHAMP!)
path=/content/geometrixx
type=nt:unstructured
property=text
property.operation=like
property.value=%<strong>%
Have a go here:
http://localhost:4502/libs/cq/search/content/querydebug.html?charset=UTF-8&query=path%3D%2Fcontent%2Fgeometrixx%0D%0Atype%3Dnt%3Aunstructured%0D%0Aproperty%3Dtext%0D%0Aproperty.operation%3Dlike%0D%0Aproperty.value%3D%25%26lt%3Bstrong%26gt%3B%25
XPath:
/jcr:root/content/geometrixx//element(*, nt:unstructured)
[
jcr:like(#text, '%<strong>%')
]
SQL2 (already covered... NASTY YUK..)
SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE([/content/geometrixx]) and text like '%<strong>%'
Although I'm sure it's entirely possible with a string of predicates, it's possibly heading down the wrong route. Ideally it would be better to parse the HTML when it is stored or published.
The required information would be stored on simple properties on the node in question. The query will then be a lot simpler with just a property = value query, than lots of overly complex query syntax.
It will probably be faster too.
So if you read in your HTML with something like HTMLClient and then parse it with a OSGI service, that can accurately save these properties for you. Every time the HTML is changed the process would update these properties as necessary. Just some thoughts if your SQL is getting too much.

How to use substring() with Import.io?

I'm having some issues with XPath and import.io and I hope you'll be able to help me. :)
The html code:
<a href="page.php?var=12345">
For the moment, I manage to extract the content of the href ( page.php?var=12345 ) with this:
./td[3]/a[1]/#href
Though, I would like to just collect: 12345
substring might be the solution but it does not seem to work on import.io as I use it...
substring(./td[3]/a[1]/#href,13)
Any ideas of what the problem is?
Thank's a lot in advance!
Try using this for the xpath: (Have the field selected as Text)
.//*[#class='oeil']/a/#href
Then use this for your regex:
([^=]*)$
This will get you the ISBN number you are looking for.
import.io only support functions in XPath when they return a node list
Your path expression is fine, but perhaps it should be
substring(./td[3]/a[1]/#href,14)
"Does not seem to work" is not a very clear description of what is wrong. Do you get error messages? Is the output wrong? Do you have any code surrounding the path expression you could show?
You can use substring, but using substring-after() would be even better.
substring-after(/a/#href,'=')
assuming as input the tiny snippet you have shown:
<a href="page.php?var=12345"/>
will select
12345
and taking into account the structure of your input
substring-after(./td[3]/a[1]/#href,'=')
A leading . in a path expression selects only immediate child td nodes of the current context node. I trust you know what you are doing.

XPath statement to assign an integer variable to the position() function in a powershell script

I am working on a Powershell script which takes as input an XML file, searches for inner text associated with a specific element/tag in that xml file, and returns the position of that element/tag, if it exists, so that the position of that element can be used to replace the inner text with some other data. For example, there may be an xml file that looks like the following . . .
<root>
<category>
<fruit>apple</fruit>
<vegetable>broccoli</vegetable>
<fruit>pear</fruit>
<vegetable>brussel sprouts</vegetable>
<fruit>orange</fruit>
</category>
</root>
So, let's say that in one part of my Powershell script I have some code to find the inner text, "orange". I would like to store in a variable the "position" integer of the "fruit" element that contains "orange" as it's inner text. So, in the above xml file, the position integer would be 3 (or 2 if starting at base zero). How would I write a proper XPath statement to access this 3rd "fruit" location through a variable? Maybe I want to access this location so that I can change "orange" to "banana" or something. I have tried the following with no success . . .
$orangePosition = ??? (I assigned a value of 3 for testing purposes)
root.SelectSingleNode("descendant::category/fruit[position()=$orangePosition]")
I have seen where "position() is assigned an integer value. I want to use a variable in place of the integer because I don't know what index in a particular file the inner text "orange" may be. Is this even possible? I've seen other posts that question similar issues, but none of them seem to work when I apply the solution (if there is one stated) to a powershell script). Any ideas on how this can be resolved?
You could use root.SelectNodes("//category/fruit[. = 'orange']/preceding-sibling::fruit).Count + 1. If you want to do it with XPath alone then use the Evaluate method e.g. root.CreateNavigator().Evaluate("count(//category/fruit[. = 'orange']/preceding-sibling::fruit) + 1"). That should return a C# double value.
It appears that I was making this harder than it needed to be. After extensive research, I have learned that there is really no need to use an index/position integer at all. I can achieve exactly what I need by doing the following . . .
root.SelectNodes('//categories/fruit') | Where-Object {$.InnerText.Contains('orange')} | foreach {$.InnerText -eq 'banana'}
But, I can still think of cases where I might want to actually know the index of the element I would like to edit so that I can exclude other, similar elements that may contain the same innertext. Anyway, this works good enough for my purposes right now. Thanks to all who responded and attempted to help.

How can I use XSL to run a template against a specific node that is located by an attribute?

For example, I'm trying to pick out the value "Application Library" from the following XML - ie, the value under content-node/localedata/title, where localedata#locale = "en".
<content-node objectid="6_NO2UF4I1186E1026H4BLVI08F1">
<localedata locale="de">
<title>Anwendungsbibliothek</title>
</localedata>
<localedata locale="en">
<title>Application Library</title>
</localedata>
<localedata locale="es">
<title>Biblioteca de aplicaciones</title>
</localedata>
</content-node>
Specifically, what XPath expression do I put in the xsl:template#match value? I think it should be something like this, except I don't know how to match for the hardcoded value "en":
<xsl:template match="localedata[#locale = en]">
Am I on the right track here, or is there some other way I should go about this?
I would say yes, you should be on the right track. I can't seem to find any samples to verify and confirm this - but you should have no trouble trying and verifying this.
I say : go for it!
Looks like you'll have to adapt your XSL just a tiny bit:
<xsl:template match="localedata[#locale='en']">
With this (remove spaces after #locale, put the value in ' ... ') everything should be fine.
Marc

Resources