I am creating an xsl file.
I want to print below code as output
<li class="td-nav-flyout {position:'containerleft'}">
But when I run the code java says "cannot compile stylesheet".
Please help.
Thanks in advance.
-Ritesh
What about the xsl:attribute element?
<li>
<xsl:attribute name="class">td-nav-flyout {position:'containerleft'}</xsl:attribute>
</li>
Use the following:
<li class="td-nav-flyout {{position:'containerleft'}}">
Normally, the curly braces inside attribute text allow you to evaluate XPath expressions. See Attribute Value Templates in the spec for full information.
Related
I'm trying to write some XSLT which basically should go through the following algorithm:
if child of current node is of type Accordion
if child of Accordion node is of type AccordionItem
take the AccordionItem's title and content and display in <div> tags
end if
end if
It seems pretty straight forward, but the code I currently have doesn't appear to be working as it should. I must be missing something, but I can't figure out exactly what. Here's my XSLT code so far:
<xsl:for-each select="$currentPage/ancestor-or-self::Home//AccordionItem[#isDoc]">
<div id="accordion">
<h3><a href='#'><xsl:value-of select="accordionItemTitle"/></a></h3>
<div><xsl:value-of select="accordionItemContent" disable-output-escaping="yes" />
</div>
</div>
</xsl:for-each>
Can anyone offer any suggestions as to why this wouldn't be working correctly? Thanks in advanced!
It seems that your XPath isn't quite behaving as you've defined in your algorithm and is navigating to the node of type Home, is that intended?
If not, try modifying the XPath to the following:
<xsl:for-each select="$currentPage/Accordion/AccordionItem[#isDoc]">
I am trying to apply regex pattern like this.
I want to apply pattern like this.
<a attributes="some set of attributes"><img attributes="some set of attribtes"/></a>
Rules:
<a> tag with attributes followed by <img> with attributes.
Sample Valid Data:
<a xlink:href="some link" title="Image" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
<img alt="No Image" title="No Image" xlink:href="soem path for image" xlink:title="Image" xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" />
</a>
Invalid:
<a>data<img/></a>--Data Present, no attributes
<a><img>abcd</img></a>--data Present, No attributes
<a><img/></a>---No attributes
Can any one suggest how to write pattern for this.
Thank you.
You can do this in a completely bulletproof manner with XPath:
//*[local-name()='a' and count(#*)>0 and *[local-name()='img' and count(#*)>0] and count(.//*)=1 and normalize-space(.)='']
This selects all elements with a local name of 'a' which have no non-significant text content, attributes, and a single 'img' element with attributes.
However, since your example code is clearly XML with namespaces and all, perhaps you can reformulate your question to say what your overall task is instead of "what regex should I use". At the very least it seems that perhaps you should be paying attention to those namespaces instead of treating namespace declarations as attributes.
For example, maybe what you really mean is this?
//xhtml:a[#xlink:href and xhtml:img[#xlink:href] and count(.//*)=1 and normalize-space(.)='']
I am trying to embed a <pre> tag in within an ordered list, of the form:
# Some content
#: <pre>
Some pre-formatted content
</pre>
But it doesn't work. Can someone please let me know on how to achieve what I am trying to do?
You can use a regular HTML list:
<ol>
<li>Some Content</li>
<li><dl><dd><pre>Some pre-formatted content</pre></dd></dl></li>
</ol>
This is the better answer for continuing a numbered list after using the <pre> tag without resorting to html:
# one
#:<pre>
#:some stuff
#:some more stuff</pre>
# two
Produces:
1. one
some stuff
some more stuff
2. two
HTML:
<dt>
<a href="#profile-experience" >Past</a>
</dt>
<dd>
<ul class="past">
<li>
President, CEO & Founder <span class="at">at</span> China Connection
</li>
<li>
Professional Speaker and Trainer <span class="at">at</span> Edgemont Enterprises
</li>
<li>
Nurse & Clinic Manager <span class="at">at</span> <span>USAF</span>
</li>
</ul>
</dd>
I want match the <li> node.
I write the Regex:
<dt>.+?Past+?</dt>\s+?<dd>\s+?<ul class=""past"">\s+?(?:<li>\s*?([\W\w]+?)+?\s*?</li>)+\s+?</ul>
In fact they do not work.
No not parse HTML using a regex like it's just a big pile of text. Using a DOM parser is a proper way.
Don't use regular expressions to parse HTML...
Don't use a regular expression to match an html document. It is better to parse it as a DOM tree using a simple state machine instead.
I'm assuming you're trying to get html list items. Since you're not specifying what language you use here's a little pseudo code to get you going:
Pseudo code:
while (iterating through the text)
if (<li> matched)
find position to </li>
put the substring between <li> to </li> to a variable
There are of course numerous third-party libraries that do this sort of thing. Depending on your development environment, you might have a function that does this already (e.g. javascript).
Which language do you use?
If you use Python, you should try lxml: http://lxml.de. With lxml, you can search for the node with tag ul and class "past". You then retrieve its children, which are li, and get text of those nodes.
If you are trying to extract from or manipulate this HTML, xPath, xsl, or CSS selectors in jQuery might be easier and more maintainable than a regex. What exactly is your goal and in what framework are you operating?
please learn to use jQuery for this sort of thing
Lets say I have the following code snippet below, how do I also apply the disable-output-escaping to the {name} in the title attribute?
<a title="{name}"><xsl:value-of select="name" disable-output-escaping="yes" /></a>
This has really got me stumped.
Thanks guys.
This cannot be done with XSLT. The spec says:
It is an error for output escaping to
be disabled for a text node that is
used for something other than a text
node in the result tree.
Thus it makes no difference if you use Attribute Value Templates or xsl:attribute with xsl:value-of, because you're generating an attribute node, not a text node. It's a limitation in the language.
You can't as is. The {name} shortcut doesn't allow additional parameters. Use the <xsl:attribute> tag instead.