Hi we have created a doc type with a tile, description and an mediaPicker uploadcontrol
Using this we have uploaded a small number of test files. We now want to list the files by title and description (done) and prvide a link which when clicked, directs the browser to upload the file from the node listed. All example we can find are for earlier versions < 4.5
and cant get them to work in 4,11.8....
the line we are having problems with is:
<a href="umbraco.library:GetMedia($currentPage/uploadFile, 'false')/umbracoFile"/>
or
<a href="umbraco.library:GetMedia($currentPage/uploadFile, 0)/umbracoFile"/>
which give a "too big" int32 error
What are we missing please?
Can you try this code:
<xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/uploadFile, 0)" />
<xsl:if test="$media">
<xsl:variable name="url" select="$media/umbracoFile" />
<xsl:variable name="width" select="$media/umbracoWidth" />
<xsl:variable name="height" select="$media/umbracoHeight" />
<img src="{$url}" width="{$width}" height="{$height}" />
</xsl:if>
You can find more info on the wiki of Umbraco: http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia
Related
I'm trying to access values from my xml file using "title" xpath without using /Para000_* because _1,_2 is dynamic.
Is there any way to access the value without using para number please help me
I need value only "Mango" but i'm getting "Mango Orange" values
I have an xml as follows:
<Content code="" title="Food" type="Fruits" paraCode="2">
<props>
<para001_2 title="F1">Mango</para001_2>
<para002_2 title="F2">Grape</para002_2>
</props>
</Content>
<Content code="" title="Food" type="Fruits" paraCode="2">
<props>
<para001_2 title="F1">Orange</para001_2>
<para002_2 title="F2">Grape</para002_2>
</props>
</Content>
tried XSLT as follows:
<xsl:variable name="FruitName" select="/Content/props/*[#title = 'F1']"/>
Result:
Mango
Use this
<xsl:variable name="FruitName" select="/Content/props/*[#title = 'F1'][not(preceding::Content/props/*[#title = 'F1'])]"/>
Please mention on what basis/condition you want access the node <Content>
For the current input given, to access the first node's title
The solution can be:
<xsl:value-of select="root/Content/props/*[1][#title = 'F1']"/>
I have a bunch of text files that I'd like to process witth XSLT 2.0.
Here's how I try to read them in:
<xsl:variable name="input" select="collection(iri-to-uri('file:///.?select=*.txt'))" />
However, when I do this:
<xsl:message>
<xsl:sequence select="count($input)"/>
</xsl:message>
It outputs 0. No files are selected.
If I do it like this:
<xsl:variable name="input" select="collection(iri-to-uri('.?select=*.txt'))" />
I get the error that collection should return a node but is returning an xs:string.
What I would like do to is read each file and then iterate over each file and process the text, like this
<xsl:for-each select="unparsed-text($input, 'UTF-8')">
<!-- tokenizing, etc. -->
How would I do that?
You need the XPath 3.0 uri-collection function supported in version="3.0" stylesheet in Saxon 9.7 (all versions including HE) and 9.6 (commercial versions I think):
<xsl:template match="/" name="main">
<xsl:for-each select="uri-collection('.?select=*.txt')!unparsed-text(.)">
<xsl:message select="'Parsed:' || . || '
'"/>
</xsl:for-each>
</xsl:template>
collection is supposed to return a sequence of nodes while uri-collection can access other resources not parsable as XML.
With Altova XMLSpy respectively RaptorXML and XSLT 3.0 you can also use uri-collection, it seems the way to access all .txt files is a bit different from Saxon and you use uri-collection('*.txt') to access all .txt files in the directory.
Having a bit of an issue with CDATA. For my current project, I had to convert a number of HTML elements into CDATA in order to be imported to a test case management system via XML. I am now tasked with exporting that data and translating it into DITA. The following is an excerpt from the data I am working with that I think provides enough context:
<tr:testopia><tr:testplan><tr:testcase>
<tr:text version="1">
<tr:author>bugzilla</tr:author>
<tr:action><![CDATA[<ol xmlns="http://www.w3.org/1999/xhtml">
<li>
<p xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:cln="http://clean/" class="Table">Refer to
<span style="color:red">CHM795_Workflow_DITA_Test_plan.doc
</span>
</p>
</li>
</ol>]]></tr:action>
<tr:expected_result><![CDATA[<ol xmlns="http://www.w3.org/1999/xhtml">
<li>
<p xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:cln="http://clean/"
class="Table">All requirements are met & example example</p>
</li>
</ol>]]></tr:expected_result>
<tr:setup><![CDATA[]]></tr:setup>
<tr:breakdown><![CDATA[]]></tr:breakdown>
</tr:text>
</tr:testcase></tr:testplan></tr:testopia>
To do this, I need to get the elements previously kept in CDATA out again, and I've found from a small amount of research that a line such as the following will achieve this:
<xsl:template match="tr:text">
<prerequisites>
<xsl:apply-templates select="tr:setup"/>
</prerequisites>
<postrequisites>
<xsl:apply-templates select="tr:breakdown"/>
</postrequisites>
<process>
<actions>
<xsl:apply-templates select="tr:action"/>
</actions>
<results>
<xsl:apply-templates select="tr:expected_result"/>
</results>
</process>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)" disable-output-escaping="yes"/>
</xsl:template>
This will provide me with the following:
<case>
<prerequisites/>
<postrequisites/>
<process>
<actions><ol xmlns="http://www.w3.org/1999/xhtml"> <li> <p xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:cln="http://clean/" class="Table">Perform <span style="color:red">ASM Test Document.docx</span> </p> </li> </ol></actions>
<results><ol xmlns="http://www.w3.org/1999/xhtml"> <li> <p xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:cln="http://clean/" class="Table">Test plan successfully completed</p> </li> </ol></results>
</process>
The issue I currently face is this: disabling output escaping gets me the format I need, translation has worked fine and the DITA file validates. However, in some of these test cases, the content of the HTML elements sometimes contain characters such as &. When I try to translate these cases into their final form after this stage, I receive an error like the following when running with SAXON:
Error reported by XML parser: The entity name must immediately follow
the '&' in the entity reference.
Is there a way I can keep the internal text of the nodes in their current "harmless" state and still wrap it in the nodes also held in CDATA? Could probably phrase that better, but the words aren't coming to mind.
So I recently started working with XSL 1.0 on a project and needed to iterate over a node-set and for each node make a call out to a template with "attributes" from the node.
I say "attributes" because I ended up just making an inner tag, ie. the node-set I'm iterating over looks like this:
<var>
<key>key 1 text here</key>
<value>value 1 text here</value>
</var>
....
<var>
<key>key Nth text here</key>
<value>value Nth text here</value>
</var>
Though I could go back to something like <var key="keytext" value="valtext" /> and use actual attributes if someone thinks that's better (in fact it's the way I first approached this issue but had no luck with it).
Anyway, this node-set is being used to populate a form. The user selects a Project Name from a dropdown menu, which populates the Plan Name dropdown menu. Once the user then selects a plan name, there is a table on the form called Build Variables that gets populated with the key/value pairings for that plan. If the user changes the plan name, then the build variables change (I've already taken care of page refresh and reload and making sure the old variables are wiped) and the number of rows in the table is likely to change (one row of the table per key/value pair).
This is the relevant portion of the XSL that gets the node-set of <var> tags and assigns it to $variables then uses a <for-each> to iterate over them, grab the key/value pairs and pass them to the template "widget_render" (I'm not putting up the widget_render code since it's extremely verbose (greater than 150 lines) and makes calls to other templates based on what params it gets passed). In this particular case, all widget_render, is essentially create a text area box and populate it with the content of the key or value - the box for the key cannot be edited by the user, but the box it creates for the value can be. Here's the code:
<xsl:variable name="variables" select="bamb-class:getPlanVariables($projVal, $planVal)" />
<xsl:for-each select="$variables">
<xsl:variable name="key" select="./key" />
<xsl:variable name="value" select="./value"/>
<tr height="30">
<td class="datacell" colspan="1">
<xsl:call-template name="widget_render">
<xsl:with-param name="fieldName" select="concat('keyField[', position(), ']')"/>
<xsl:with-param name="renderCmd" select="'input'" />
<xsl:with-param name="default" select="$key" />
<xsl:with-param name="readOnly" select="'true'" />
</xsl:call-template>
</td>
<td class="datacell" colspan="1">
<xsl:call-template name="widget_render">
<xsl:with-param name="fieldName" select="concat('valueField[', position(), ']')"/>
<xsl:with-param name="renderCmd" select="'input'"/>
<xsl:with-param name="default" select="$value" />
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
Hopefully that's enough background on what I'm doing so that this makes sense. Let me know if it doesn't.
My issue is this: the key and value seem to get lost inside the call-template to widget_render. Meaning that no input box with text appears in either <td> tag in the table.
However I can do <xsl:value-of select="$key" /> and <xsl:value-of select="$value" /> inside the appropiate <td> tag and it outputs the correct value (the information is there, just not being passed into widget_render or something).
With no value-of statements all I'm currently getting are the correct number of rows, but they're all blank.
And yes, I have to use the widget_render template (can't just put in an <input> tag or something) since the software later re-uses the widget_render logic on the table to perform other operations. And no, it's not a type clash or something where I pass in a wrong type, I made sure of that.
I don't know if it's something really asinine that I am missing or if there's something larger that I just don't understand, but this one has me stumped.
So to put it succinctly: Why is the call-template (seemingly) not working and populating the table with the key/value pairs in the for-each loop? Even when I know the for-each is iterating over the correct node-set and $key and $value have the correct assignments at each iteration.
Any help on this would be much appreciated, thanks! Let me know if anything is unclear or if there's any information I unwittingly left out that needs to be known. If needed I could throw up the widget_render code as well, but I doubt that would actually be helpful to anyone.
EDIT:
Here's a link to a dropbox with the whole file: widget_render starts on line 119
https://www.dropbox.com/s/zt3g9idprrca6ak/default-widgets.xml
It's a very long template, and all the other templates it calls are in that file as well.
So I managed to figure out a solution - seems kind of like a hack to me, but it works and works well for what I need.
I replaced the loop with this:
<xsl:variable name="planVariables" select="bamb-class:getPlanVariables($projVal, $planVal)"/>
<xsl:call-template name="renderAllRows">
<xsl:with-param name="i" select="1"/>
<xsl:with-param name="count" select="count($planVariables)"/>
<xsl:with-param name="planVariables" select="$planVariables"/>
</xsl:call-template>
Which then makes a call out to renderAllRows which recursively calls itself to simulate the xsl:for-each loop until all the rows in the table have been rendered.
<xsl:template name="renderAllRows">
<xsl:param name="i" />
<xsl:param name="count" />
<xsl:param name="planVariables" />
<xsl:if test="$i <= $count">
<xsl:call-template name="renderRow" >
<xsl:with-param name="rowNum" select="$i"/>
<xsl:with-param name="planVariables" select="$planVariables"/>
</xsl:call-template>
</xsl:if>
<!-- recursion here -->
<xsl:if test="$i <= $count">
<xsl:call-template name="renderAllRows">
<xsl:with-param name="i" select="$i + 1"/>
<xsl:with-param name="count" select="$count"/>
<xsl:with-param name="planVariables" select="$planVariables"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="renderRow">
<xsl:param name="rowNum"/>
<xsl:param name="planVariables"/>
<xsl:variable name="key" select="exsl:node-set($planVariables)[position()=$rowNum]/key"/>
<xsl:variable name="value" select="exsl:node-set($planVariables)[position()=$rowNum]/value"/>
<tr height="30">
<td class="datacell" colspan="1">
<xsl:call-template name="widget_render">
<xsl:with-param name="fieldName" select="concat('keyField[', $rowNum, ']')"/>
<xsl:with-param name="renderCmd" select="'input'" />
<xsl:with-param name="default" select="$key" />
<xsl:with-param name="readOnly" select="'true'" />
</xsl:call-template>
</td>
<td class="datacell" colspan="1">
<xsl:call-template name="widget_render">
<xsl:with-param name="fieldName" select="concat('valueField[', $rowNum, ']')"/>
<xsl:with-param name="renderCmd" select="'input'"/>
<xsl:with-param name="default" select="$value" />
</xsl:call-template>
</td>
</tr>
</xsl:template>
And that got everything working properly, the calls out to widget_render are looking at the right context, creating the textboxes they should and populating them. Thanks to Jirka for the tips that helped me fix this.
in my umbraco setting, i dont have any image logo to upload my image that was saved in my Media folder, only insert umbraco page field and insert umbraco macro logo was there.I tried many links but it was unsuccessful.im using umbraco V3.0.5
If I understand you correctly, you're modifying a template (you have access to insert field and insert macro) and you want to add an image that is saved in your media section.
Are you really using Umbraco 3 - that is a few years old now and the syntax is very different and you will probably need to use xslt; for example inserting a macro will look different on your template for v3 and v4 (v5 has been deprecated and v6 is not live yet).
(http://our.umbraco.org/wiki/reference/templates/umbracomacro-element/macro-parameters/advanced-macro-parameter-syntax)
Umbraco Version 3:
<?UMBRACO_MACRO macroAlias="RenderProperties" pageValue="[#bodyText]" />
Umbraco Version 4:
<umbraco:macro alias="RenderProperties" pagevalue="[#bodyText]" runat="server"/>
In the older versions of umbraco putting an image onto a page from media required writing some xslt and referring to it in a macro - this example (that I've dredged up) would display the image that was picked for a page with an alias of 'imageAliasName'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:umbraco.contour="urn:umbraco.contour" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour PS.XSLTsearch ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="mediaId" select="number($currentPage/imageAliasName)" />
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="$mediaNode/umbracoFile">
<img>
<xsl:attribute name="src">
<xsl:text>/ImageGen.ashx?image=</xsl:text>
<xsl:value-of select="$mediaNode/umbracoFile"/>
<xsl:text>&width=200</xsl:text>
<xsl:text>&height=200</xsl:text>
</xsl:attribute>
</img>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
in V3 i insert that image in to one of my content file from there i can view the id for my image..using that id image to write my code in my setting..when i write my image logo was viewed successful.