Creating XSLT dynamic twitter bootstrap - xslt

I am having a slight problem with making a twitter bootstrap dynamic in XSLT. I don't even know if what I am doing is possible as the variables in XSLT are not changeable. Here is my code:
<xsl:for-each select="category">
<div class="accordion-heading">
<a class="accordion-toggle" data-parent="#accordion2" data-toggle="collapse" href="#collapseOne">
<xsl:value-of select="title"/>
</a>
</div>
Basically, for each category, I need a new href to be created. Right now, it is set to collapseOne. I have tried a number of things such as position() to try to make this dynamic, but I cannot figure it out. Any input would be appreciated. If clarification or more code is required, please say so. I am new to posting on this forum. Thanks

The standard XSLT function generate-id() was created having in mind exactly this class of use-case scenarios.

Related

Please suggest correct regular expression for below situation

I have following response section.
06S
</td><td>
<img src="/Media/Images/Opr/2.png" title="Pa" />
</td><td style="0">
4
</td>
I want to extract 06S and 2 only if value in between tag is NOT 0.
I wrote following regular expression but it does not work. could anyone please help.
(?s)(.+?)
</td><td>
<img src="/Media/Images/Opr/(.+?).png" title="(.+?)" />
</td><td style="0">
([1-9]{1})
</td>
I didn't put a lot of time into making this pretty or anything but this will do what you asked.
<a href="\/Public\/Details\/(.+?)\?OID=(.+?)" .*?>.*?<\/a>\s*<\/td><td>\s*<img.*?\/>\s*<\/td><td.*?>\s*(?:[^\s0]|[^\s]{2,})?\s*<\/td>
This assumes that your data is coming in an extremely similar way that you posted in the question. I'm a little preoccupied so I couldn't make it much better.
obligatory regex101 link

XSLT: Getting XML namespace as an attribute

I have the following xml:
<article article-type="research-article">
<body>
<graphic xlink:href="zee9991370930006.g.eps"/>
<self-uri xlink:title="pdf" xlink:href="zee00813002857.pdf" />
</body>
</article>
I need to convert this to:
<article article-type="research-article" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML">
<body>
<graphic xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="zee9991370930006.g.eps"/>
<self-uri xlink:title="pdf" xlink:href="zee00813002857.pdf" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</body>
</article>
I used the following command in XSLT 2.0 for each of the elements for which namespace attribute is required:
<xsl:namespace name="xlink" select="'http://www.w3.org/1999/xlink'"/>
<xsl:namespace name="mml" select="'http://www.w3.org/1998/Math/MathML'"/>
But the issue is I am getting the namespace attribute only for one element i.e. article. I have declared the namespaces at the beginning of my xslt as well. Can't figure out what is the exact issue. Help of any kind would be truly appreciated. Thanks.
XML generators are not supposed to do what you want. They will produce your XML according to the specs. It is not recommended that you define the same namespaces in all elements that are using them! this makes it verbose, ugly and weird way of doing tings.
What is the problem if the namespace is defined only at the top (root element)? You can use it only in the elements that require it. simple.
(OP's comment: I need it at the root and I have declared it. But it is not available for the nodes under it i.e graphic and self-uri in my case).
Have you checked if you xml is well-formed? If what you post here is the complete xml, then graphic and self-uri should always have the namespace available. You should aim for the following output for the reasons told above.
<article article-type="research-article" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML">
<body>
<graphic xlink:href="zee9991370930006.g.eps"/>
<self-uri xlink:title="pdf" xlink:href="zee00813002857.pdf"/>
</body>
</article>

Incremental counter for <li> tags in XSLT

I'm using XSLT to pull some data from child nodes in an Umbraco (4.7) structure. That part is working fine, but I need to style each <li> item slightly different, so each one will be: <li id=x> where x is an integer between 1 and 15.
I've found a couple of methods for incrementing a counter value in XSLT, but I can't tell why it's not working as it should. Here's the relevant source:
<ul>
<xsl:for-each select="$currentPage/Solutions/SolutionsItem[#isDoc]">
<xsl:variable name="count">
<xsl:number/>
</xsl:variable>
<li id="$count">
<a><xsl:value-of select="solutionsItemTitle" /></a>
</li>
</xsl:for-each>
</ul>
When I review the HTML's source after running the XSLT, it just shows <li id=$count> rather than an integer. Can anyone suggest where to go from here?
You need an attribute value template <li id="{$count}">...</li> to compute the attribute value from the XPath expression.

Umbraco : displaying an image using the XSLT

I'm pretty new to umbraco but found the system pretty easy to use and have done alot in a short space of time. One difficulty I have come accross is displaying an image.
In the document type I have added an "upload" where an image is selected.
In my XSLT I loop through the pages, this loop displays the other fields such as description or title. I am trying to display the image here.
Here is my XSLT for displaying my image, this displays nothing. The field "promothumbImage" is defined in the document type, as I said everything else is working fine.
<xsl:value-of select="promothumbImage"/>
Does anyone have any ideas as to where I am going wrong?
EDIT:
promothumbimage is defined in the document of type "upload"
My XSLT:
<!-- The fun starts here -->
<div class="promoitems">
<xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [#isDoc and
string(umbracoNaviHide) != '1']">
<div class="promoitem">
<a href="{umbraco.library:NiceUrl(#id)}">
<xsl:value-of select="#nodeName"/>
</a>
<div class="promosmalldesc">
<xsl:value-of select="promoSmallDesc"/>
</div>
<xsl:copy-of select="promothumbImage/*"/>
</div>
</xsl:for-each>
Upload means that the element promothumbImage returns the URL of the image, thus the following should display it on the page:
<img src="{promothumbImage}" alt=""/>
I found the answer, use:
<img src="{promothumImage}" />
to display the image from the "upload" set in the document type
use may simply in your template using your image field throght Media picker Data Type:
<img class="className" src='<umbraco:Item field="infoGraphic" runat="server" Xslt="umbraco.library:GetMedia({0},false())/umbracoFile"/>'/>

Templating regex versus DOM nodes; Modifying attributes?

I've asked a few questions as of recent on this topic, and whether answered or not, I've been learning a fair amount about the tech involved. In any case;
I've been reworking a templating engine I had created previously, moving the parsing engine from being regular expression driven, to node (XML) driven. For comparison's sake here are the two:
Regex driven:
<body>
<!-- {{ region:myRegion }} -->
<div class="myClass">
<h1>{{ var:myHeading format:trim[200] }}</h1>
</div>
<!-- {{ region:myRegion }} -->
</body>
Node driven:
<body>
<zuq:region name="myRegion">
<div class="myClass">
<h1>
<zuq:data name="myHeading">
<zuq:format type="trim">
<zuq:param name="length" value="200" />
</zuq:format>
</zuq:data>
</h1>
</div>
</zuq:region>
</body>
Now while much more verbose, I figure the node driven approach here is preferred, giving much more flexibility for situations like formatting, where multiple format nodes can be inserted and processed in order of appearance.
Anyways, my problem lies in attributes. With the regex driven approach, if I want to have a template generated value in an attribute, it's as simple as:
Link
I'm trying to figure out how to incorporate a clean implementation of generating attribute values, while keeping the documents well formed. Something to consider is again, the formatting options, among other possible elements that the parser would read as modifiers to data.
Any ideas?
<a>
<zug:attr name="href">page.php?param=<zug:data name="myParam" /></zug:attr>
Link
</a>