XPath code to get value in a list - xslt

lets say I have this XML :
<myxml>
<Labels>
<Label>
<id>id1</id>
<value>abc</value>
</Label>
<Label>
<id>id2</id>
<value>def</value>
</Label>
<Label>
<id>id3</id>
<value>ghi</value>
</Label>
<Label>
<id>id4</id>
<value>jkl</value>
</Label>
<Label>
<id>id5</id>
<value>mno</value>
</Label>
</Labels>
</myxml>
And I would like to display the value "def" and "jkl".
I'm looking for the XPath expression that allow me to take the value of a label where the id is "id2".
I've tried with this :
<xsl:value-of disable-output-escaping="yes" select="Labels/Label[id = 'id2']/value"/>
but it's not working ...
Is there a way to do that ?
Thanks in advance for your answer,
Best regards

Have you tried adding the root to your xpath?
<xsl:value-of select="myxml/Labels/Label[id = 'id2']/value" />
Also, disable-output-escaping is typically unnecessary.

Related

copy id="uniqueid" as name="uniqueid" with find/replace & regex in notepad++

I have a HTML form which currently has unique id's for each input (or select) like so.
example 1
<input type="number" id="qty-a-row" min="0" max="999" autocomplete="off" value="" style="border:0px; outline:0px; display:inline-block; width:50px;" />
example 2
<select id="ps_a_row" autocomplete="off" style="width:324px; border:0px; outline:0px; display:inline-block">
each id is unique. I'm now trying to add in a name="" with the same value as every id="" found so example 1 above becomes.
<input type="number" id="qty-a-row" name="qty-a-row" min="0" max="999" autocomplete="off" value="" style="border:0px; outline:0px; display:inline-block; width:50px;" />
and example 2 becomes...
<select id="ps_a_row" name="ps_a_row" autocomplete="off" style="width:324px; border:0px; outline:0px; display:inline-block">
and so on for every id="anything" it finds.
I'm using notepad++ and with regex ticked currently trying...
Find = id="(.*)"
Replace = id="\1" name="\1"
but this is only finding some id's and duplicates all other tags it finds after the id it finds too.
The complete code for the form I'm trying to edit is here...
https://pastebin.com/ZAE4Gffk
Find id="([^"]+)" and replace it with id="\1" name="\1" , but you shouldnt use regex for HTML manipulation. Use appropriate tools for that.
Demo

xsl loop with new name for template tag

I am trying to use a loop iteration in xslt. I want to loop through all the text with tei of "orgName", and generate a different popover-body for each one. I hope it would be something like (div class="Org-popover-body-1),(div class="Org-popover-body-2)... What should I put in ??? Thanks beforehand.
<xsl:template match="tei:orgName">
<xsl:for-each select="orgName">
<a class="orgName" id="orgNameinfo" data-toggle="popover-2" data-trigger="fcours" data-popover-content-2="#a2" data-placement="right">
<xsl:attribute name="href">
<xsl:text>#</xsl:text>
<xsl:value-of select="#key" />
</xsl:attribute>
</a>
<div id="a2" class="hidden">
<div class="popover-heading2">Orgnization Information <span style="float:right;cursor:pointer;" class="fa fa-times" data-toggle="popover"></span>
</div>
<div class="Org-popover-body-???">
</div>
</div>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:template>
I think what you need are Attribute Value Templates, so you would write this...
<div class="Org-popover-body-{position()}">
You probably want to do this in the id of the hidden div to (to avoid multiple divs with the same id)
<div id="a{position()}" class="hidden">
And similarly in the data-popover-content-2 attribute
... data-popover-content-2="#a{position()}" ...

Selenium Python XPATH I am trying to find the input tag which has some text in the title attribute

I have a HTML page with some checkboxes with a name beside it. Using XPATH I can locate the checkbox which has the complete text in the title attribute using = to match the complete text.
E.g.
//div[#id="operations_add_process_list_tab_groups_tab_standard_1"]//span//input[#title="CRM : crm"]
I don't want to match the whole text, I would like to find it by using some of the text e.g. I would like to find the checkbox where "CRM" in the title attribute.
I don't want to use "CRM : crm"
Can i use the contains keyword to find where "CRM" is in the title attribute?
I do not know the syntax for this.
I tried: //div[#id="operations_add_process_list_tab_groups_tab_standard_1"]//span//input[#title[contains(text(), CRM : crm")]]
The HTML is:
<div id="operations_add_process_list_tab_groups_tab_standard_1">
<span>
<span>
<span/>
<span>
<span/>
<span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;">
<input type="checkbox" checked="" title="CRM : crm" tabindex="-1"/>
CRM : crm
</span>
</span>
<span>
<span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;">
<input type="checkbox" checked="" title="ESCR : escr" tabindex="-1"/>
ESCR : escr
</span>
</span>
<span>
<span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;">
<input type="checkbox" checked="" title="ORCHARD : orchard" tabindex="-1"/>
ORCHARD : orchard
</span>
</span>
Thanks,
Riaz
The contains is what you are looking for. In your case.
//input‌​[contains(#title, "CRM")]
contains can be used for any attribute and for text in the element as well.

How to automatically assign value to an attribute using XSLT in for-each loop?

In a for-each XSLT loop I construct an HTML structure of the form:
<div class="panel-group" id="accordion1" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading001">
...
</div>
</div>
</div>
Is it possible in that loop to generate the suffix of the attributes id and assign to it? So that in first loop the IDs become "accordion1" and "heading001", in the second loop become "accordion2" and "heading002", etc? And if so, can you provide an example?
in your for each loop, example for the id do something like below
<xsl:attribute name="id">
<xsl:value-of select="concat('accordion', position()" />
</xsl:attribute>

Append text to value-of XLST function

How would you append text to value-of function. Is it possible? I want to append -button after substring(b:id,1):
<input type="button" class="btn btn-primary" data-toggle="modal" value="Check Price">
<xsl:attribute name="id">
<xsl:value-of select="substring(b:id,1)"/>
</xsl:attribute>
</input>
You can put several value-of and/or xsl:text instructions inside an xsl:attribute, but simpler would be to use the concat function in an attribute value template, which is much less verbose. You only really need xsl:attribute when you're creating an attribute with a computed name rather than a fixed one.
<input id="{concat(substring(b:id, 1), '-button')}" type="button" class="btn btn-primary" data-toggle="modal" value="Check Price"/>
Or just:
<input id="{b:id,1}-button" ... "/>
since anything outside of curly braces is literal text, and substring($string, 1) is the same thing as $string.