I use Altova XMLSpy and Saxon. Saxon adds a lot of tabs and Newlines in the result file. So I added the templates (found here on stackoverflow):
<xsl:template match="*/text()[normalize-space()]">
<xsl:value-of select="normalize-space()"/>
</xsl:template>
<xsl:template match="*/text()[not(normalize-space())]" />
to the stylesheet, which neatly removed all extra white space. However, it also removed the space before and after the <i>....</i> and <q>....</q> inside a <p>:
<p>this is <i>italic</i> text</p>
So both Altova and Saxon gave me:
<p>this is<i>italic</i>text</p>
How can I solve this problem?
Use the xsl:output element to control indentation of the output. Use xsl:strip-space and xsl:preserve-space to control whitespace handling of your input.
Use templates like the two you show only as a last resort. Here, the first template is the one causing the loss of whitepace adjacent to your i elements, because the processors are doing what you told them to do, instead of what you meant to tell them to do.
Related
I am trying to extract the value attribute of XML tag in Tridion rich text editor.
I am trying to add this code to filtering XSLT. But it is not working.
<xsl:template match="dynamicVariable">
<dynamicVariable name="{//dynamicVariable/#name}"/>
</xsl:template>
I wonder if you can give a more concrete example of what you are trying to achieve. I believe the XSLT is applied when you paste content into the field, when you change tabs (from source to design) and when you save.
I'm facing some problems using CDATA blocks inside h:outputscripts with MyFaces 2.0... but I don't know exactly if I should avoid using CDATA with JSF2 or if it is because I do things wrong.
Maybe it is because I use many scripts in many Composite components...
The fact is that when I have some composite components that contain scripts with surrounded by CDATA blocks, other scripts in the page doen't work.
Removing CDATAs solves the issue.
Nevertheless I've had an issue where using CDATA blocks made some of my Composite components bug saying a property of the component can't be found on class NamingContainer when trying to render the component using f:ajax render attribute. Here is the workaround.
Removing the CDATA surrounding my scripts solved the problem.
So my question is : am I the only one having troubles with CDATA blocks and JSF2 (MyFaces) ?
This is a known issue. See MYFACES-3339 for details. It was already fixed, so you can try the latest code HERE, and it will be included on 2.1.4 and 2.0.10.
I can't answer if you're the only one having problems with it. I can at least answer that having JS code plain in a XML file is a poor practice. JS code is not well formed XML. Fiddling with escaping XML-special characters in JS code or putting JS code in CDATA blocks is plain ugly. That it gives troubles in JSF ajax response is in turn a different story. Technically, that would have been a bug in the JSF implementation used. But from the other side on, you're actually practicing a poor practice.
Just put JS code in its own .js file which you reference by <h:outputScript>.
<cc:implementation>
<h:outputScript library="foo" name="js/your-cc-script.js" target="head" />
...
</cc:implementation>
I have 2-3 HTML files created per week that will be uploaded via FTP to a folder on the web server. The files are just plain HTML having results from my local Bridge Club.
Before I go ahead and spending time creating a "fancy" solution in .Net for this I better ask if there is any built in support for this in Umbraco.
Basically I want to have a main menu item called Results, and that page should have a secondary menu with links to each .HTML file in a specific folder
Any ideas?
Cheers,
Stefan
First, make sure you put the path that the html files are being uploaded to within the umbracoReservedPaths app setting in the web.config.
Next I would create an XSLT extension (or custom function that returns an XPathNodeIterator containing each HTML file name. The method will need to build an XmlDocument that looks something like:
<files>
<file>/htmlfiles/file1.html</file>
<file>/htmlfiles/file2.html</file>
<file>/htmlfiles/file3.html</file>
</files>
Then call CreateNavigator() on the XmlDocument and return that from the XSLT extension method. Use Directory.GetFiles to get the list of HTML file names and convert them to a web ready URL like /htmlfiles/file1.html.
Then display it all with a simple XSLT macro that iterates the result of your XSLT extension in a for-each. That would look something like:
<xsl:for-each select="customExtensions:GetFiles()//file">
<a>
<xsl:attribute name="href">
<xsl:value-of select="." />
</xsl:attribute>
<xsl:text>File #</xsl:text>
<xsl:value-of select="position()" />
</a>
</xsl:for-each>
This would generate a list like
File #1
File #2
File #3
all linking to their respective value in the xml.
A good example of an extension method is here
So, I have a stylesheet that spends most of its time transforming elements from 'namespace a' to the xhtml namespace.
In one particular case, however, I want to allow the input vocabulary to include any xhtml element. From a schema standpoint, I've added an <xs:any namespace="...."/> for the xhtml namespace.
It looks like:
<btml:html-noscript xmlns="http://www.w3.org/1999/xhtml">
<div style="display:inline;">
<img height="1"
width="1"
style="border-style:none;"
alt=""
src="http://www.googleadservices.com/pagead/conversion/1070015830/?label=FoKlCKDxiAIQ1sqc_gM&guid=ON&script=0"/>
</div>
</btml:html-noscript>
The stylesheet uses xsl:copy-of to copy the children of the passthrough element into the output.
Saxon-B, which I am using (last release), seems sort of stupid about the namespaces. Even though the target namespace of the entire output document is the xhtml namespace, the output looks like:
<noscript>
<div xmlns:btml="http://www.basistech.com/2010/btml/"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
style="display:inline;">
<img height="1"
width="1"
style="border-style:none;"
alt=""
src="http://www.googleadservices.com/pagead/conversion/1070015830/?label=FoKlCKDxiAIQ1sqc_gM&guid=ON&script=0"></img>
</div>
</noscript>
Note the pointless prefixes, instead of just putting out <div ...>. Note that the document element of the whole business ('html') defines xmlns="ttp://www.w3.org/1999/xhtml".
Is there any way to neaten this up?
Try whether doing <xsl:copy-of select="node()" copy-namespaces="no"/> helps (see http://www.w3.org/TR/xslt20/#copy-of). If not then please post complete samples of XML input, and XSLT stylesheet allowing us to reproduce the problem, your snippets so far do not explain where for instance the xmlns:xhtml="..." in the result snippet on the div element comes from.
From http://www.w3.org/TR/xml-names/#scoping
The scope of a namespace declaration
declaring a prefix extends from the
beginning of the start-tag in which it
appears to the end of the
corresponding end-tag, excluding the
scope of any inner declarations with
the same NSAttName part. In the case
of an empty tag, the scope is the tag
itself.
For your case, it means that "http://www.basistech.com/2010/btml/" and "http://www.w3.org/1999/xhtml" namespace URIs bound to btml an xhtml prefixes are in scope for your div element unther "http://www.w3.org/1999/xhtml" default namespace.
Of course, as suggested by #Martin Honnen's answer xsl:copy-of/#copy-namespaces with "no" as value will strip in scope namespace not actually used (i.e. in this element or its attribute's names).
From the docs, XSL processor can be used to dynamically generate href links (or other HTML content):
<xhtml:tr>
<xhtml:td>
<xsl:for-each select="{instance('fr-form-instance')/form/retrievalSection/retrievalControl">
<xhtml:a href="http://somewhere/">
<xsl:value-of select="SomeData"/>
<xsl:if test="position() lt last()">
<br/>
</xsl:if>
</xhtml:a>
</xsl:for-each>
</xhtml:td>
The above is just rough example code, that href is static in above can be ignored.
The problem is this (xslt generated link text) does not get updated automatically upon instance update; how to achieve that?
XSLT processing is done once and for all when the page loads. You can see the XSLT step as a template or preprocessing step. Once that's done, XForms processes the result, and then things get dynamically updated.
You can mix XSLT and XForms this way, but it's not trivial and if you can it's probably best to avoid it.
I would try using XForms exclusively to achieve this instead, something like:
<xhtml:td>
<xforms:repeat nodeset="instance('fr-form-instance')/form/retrievalSection/retrievalControl">
<xhtml:a href="http://somewhere/">
<xforms:output value="SomeData"/>
<xhtml:br/>
</xhtml:a>
</xforms:repeat>
</xhtml:td>
If you want the href to be dynamic, use an AVT like in XSLT:
href="{expression}"
Finally, you could put the <br/> within an <xforms:group> to make it conditional, but it's probably better to use CSS in this case if you can.