Append text to value-of XLST function - xslt

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.

Related

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()}" ...

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>

How can I use search replace in visual studio with regular expression?

In the find input of visual studio I have this expression
<input type="submit" value=(.*) />
And in the replace one I have
<input type="submit" value=(\1) a />
But for some reason instead of adding an "a" it is literally replacing the code.
I mean, I am getting this
<input type="submit" value=(\1) a />
instead of this
<input type="submit" value="Change password" a />
I am using Visual Studio 2012 Express for Web
In the replacement string, you need to use $1. \1 is for backreferences within the search pattern. You'll also want to omit the parentheses in the replacement string.
<input type="submit" value=$1 a />
To make your pattern a bit more robust you might want to use something like
<input type="submit" value=("[^"*]") />
For the pattern. Otherwise you'll get problems if you have another self-closing tag on the same line, or an input tag with more attributes.

XPath code to get value in a list

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.

How to embed ${ text } into a XSLT

Thank you for taking the time to look at my post.
I have an input tag that i need to have output-ed like so:
<input type="hidden" name="success_redirect" value="http://www.webpage.com?var1=${root/option1}&var2=${root/option2}" />
but i cant get that into my xslt document without it eventually rendering to
<input type="hidden" name="success_redirect" value="http://www.webpage.com?var1=$&var2=$" />
What do i put in the XSLT to allow me to get that value tag to output like i need it to?
Thanks!
Just use:
<input type="hidden" name="success_redirect"
value="http://www.webpage.com?var1=${{root/option1}}&var2=${{root/option2}}" />
Do note that if we want to output a '{' or a '}' in an attribute, we have to double them.
This is because these two characters have special meaning when used inside an attribute: they indicate the start and end of an AVT (attribute-value-template).
You can concatenate the parts:
<input type="hidden" name="success_redirect"
value="{concat('http://www.webpage.com?var1=${','root/option1}','&var2=${','root/option2}')}" />