I need help please.
No clue in xml & WebtextEdit, I am editing an xslt stylesheet that creates asp controls.
Below is the WebTextEdit control, I want to add an mousemove event:
<xsl:element name="igtxt:WebTextEdit">
<xsl:attribute name='id'><xsl:value-of select='$Name' /></xsl:attribute>
<xsl:attribute name='runat'>server</xsl:attribute>
<xsl:attribute name='Text'><xsl:value-of select='$Value' disable-output-escaping="yes" /></xsl:attribute> <xsl:attribute name='MouseMove'>"<xsl:value-of select='#name' />".style.color = '#006AB6';</xsl:attribute>
<xsl:for-each select="$Attributes/Attribute">
<xsl:if test=". != ''">
<xsl:attribute name='{#name}'><xsl:value-of select='.' /></xsl:attribute>
</xsl:if>
</xsl:for-each>
<xsl:copy-of select="$Events" />
</xsl:element>
The code works to change the style as it works on other objects.
Please assist with how i can add a mouseover event to WebTextEdit control
If you always want to run the same (static) JavaScript or dynamic JavaScript generated with XSLT, use the same method as is used to add the id, runat, and Text attributes:
<xsl:attribute name="mouseover">alert('test');</xsl:attribute>
If each control needs to execute different (static) JavaScript, just add an onmouseover attribute to the XML element that triggers this template. The loop will read any attributes in the XML element and pass them on to the generated markup.
Related
I have a variable #expectedLength. I need to assign it to a style attribute.
<xsl:if test="#expectedLength">
<xsl:attribute name="style">
<xsl:value-of select="'width:200px'"/>
</xsl:attribute>
</xsl:if>
I need to replace 200 with the value of #expectedLength. How can I use the variable?
You could change your snippet to
<xsl:if test="#expectedLength">
<xsl:attribute name="style">width: <xsl:value-of select="#expectedLength"/>;</xsl:attribute>
</xsl:if>
That should work with any version of XSLT.
In XSLT 2 and later you can also use the select expression
<xsl:if test="#expectedLength">
<xsl:attribute name="style" select="concat('width: ', #expectedLength, ';')"/>
</xsl:if>
I would prefer to and suggest to set up a template
<xsl:template match="#expectedLength">
<xsl:attribute name="style" select="concat('width: ', #expectedLength, ';')"/>
</xsl:template>
and then to make sure higher up that any attribute nodes are processed.
This is how the my search results page of DSpace looks like :
On clicking the item a new page opens up showing its description:
The description page opens the file upon clicking View/Open. Is it possible to directly open the file upon clicking its title on the results page? I want to skip the item description page.
As per my understanding this is the Java file which is called to render items. Do I need to make changes to this file? Or is it possible to achieve what I want by simply modifying the sitemap and xsl files?
The code that generates the thumbnail image is here.
https://github.com/DSpace/DSpace/blob/dspace-6_x/dspace-xmlui/src/main/webapp/themes/dri2xhtml/General-Handler.xsl#L34-L47
You could create similar logic to create an href to the original bitstream.
Look at the XML in /metadata/handle/xxx/yyy/mets.xml where xxx/yyy is your item handle. You should see the information that will point you to the original bitstream.
As was said in the comments, the xsl template to modify is the "itemSummaryList" in discovery.xsl
Replace that href value with $metsDoc//mets:FLocat[#LOCTYPE='URL']/#xlink:href"
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="$metsDoc//mets:FLocat[#LOCTYPE='URL']/#xlink:href"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="dri:list[#n=(concat($handle, ':dc.title')) and descendant::text()]">
<xsl:apply-templates select="dri:list[#n=(concat($handle, ':dc.title'))]/dri:item"/>
</xsl:when>
<xsl:otherwise>
<i18n:text>xmlui.dri2xhtml.METS-1.0.no-title</i18n:text>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
I was able to achieve what I wanted with help from Antoine Snyers, terrywb and this link. As pointed out by terrywb the information which I needed to read, i.e, the bitstream address of the uploaded file, was stored in the metsDoc. Here's a screenshot of my metsDoc with the fileSec expanded:
To be able to access the fileSec of the metsDoc I changed this line in discovery.xsl and this line in common.xsl to <xsl:text>?sections=dmdSec,fileSec&fileGrpTypes=ORIGINAL,THUMBNAIL</xsl:text>.
Then I added/modified the following code to the itemSummaryList in discovery.xsl so that the title hyperlink now points to the file bitstream.
<xsl:variable name="filetype">
<xsl:value-of select="$metsDoc/mets:METS/mets:fileSec/mets:fileGrp[#USE='CONTENT']"/>
</xsl:variable>
<xsl:variable name="fileurl">
<xsl:value-of select="$metsDoc/mets:METS/mets:fileSec/mets:fileGrp[#USE='CONTENT']/mets:file/mets:FLocat[#LOCTYPE='URL']/#xlink:href"/>
</xsl:variable>
<div class="artifact-title">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:choose>
<xsl:when test="$metsDoc/mets:METS/mets:dmdSec/mets:mdWrap/mets:xmlData/dim:dim/#withdrawn">
<xsl:value-of select="$metsDoc/mets:METS/#OBJEDIT"/>
</xsl:when>
<xsl:when test="$filetype">
<xsl:value-of select="$fileurl"/>
</xsl:when>
</xsl:choose>
</xsl:attribute>
Similarly, I also made changes to item-list.xsl file, and added this line <xsl:apply-templates select="mets:fileSec/mets:fileGrp[#USE='CONTENT']"
mode="itemSummaryList-DIM"/> to the template itemSummaryList-DIM.
So finally I got my desired result:
As visible in the inspector, the href attribute of the title now points to the original bitstream of the file :)
I have a comma separated list coming from C#, which I am parsing in XSLT and loading it as drop down. After the user selects the option from the drop down and submits the page, If other fields are not filled in the page, I try to reload the page with the selected option for this drop down.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="parseString">
<xsl:param name="list"/>
<xsl:if test="contains($list, ',')">
<xsl:element name="option">
<xsl:attribute name="value">
<xsl:value-of select="substring-before($list, ',')"/>
</xsl:attribute>
<xsl:value-of select="substring-before($list, ',')"/>
<xsl:if test="substring-before($list, ',')=$carrier">
: sel value
<xsl:attribute name="SELECTED"></xsl:attribute>
</xsl:if>
</xsl:element>
<xsl:call-template name="parseString">
<xsl:with-param name="list" select="substring-after($list, ',')"/>
</xsl:call-template>
</xsl:if>
But upon reload, the selected value in the drop down is not maintained.
But I can see the text - 'sel value' meeting the condition and displayed. For example in the Image you can see the text for carrier - Metro PCS.
Any Help would be appreciated.
Thanks.
EDIT: I have tried multiple ways for selected attribute like
<xsl:attribute name="SELECTED"></xsl:attribute>
<xsl:attribute name="SELECTED">True</xsl:attribute>
<xsl:attribute name="SELECTED">selected</xsl:attribute>
None of them seem to work.
Try swapping these two lines:
: sel value
<xsl:attribute name="SELECTED"></xsl:attribute>
to be
<xsl:attribute name="SELECTED"></xsl:attribute>
: sel value
I think you are trying to add an attribute to the ": sel value" text node which obviously won't work.
EDIT
Taking a closer look at your template I think it is an issue like suggested above (adding an attribute to a text node).
Try this:
<xsl:element name="option">
<xsl:attribute name="value">
<xsl:value-of select="substring-before($list, ',')"/>
</xsl:attribute>
<xsl:if test="substring-before($list, ',')=$carrier">
<xsl:attribute name="SELECTED"></xsl:attribute>
: sel value
</xsl:if>
<xsl:value-of select="substring-before($list, ',')"/>
</xsl:element>
When your if is true it is trying to add an attribute to the text node added by the value-of. All of your attribute additions need to come before adding any child nodes, be they text or otherwise.
Problem I have is I want to loop round the parents making them bold then get the children via the id:pid (parent id) and list them. My second loop doesn't work.
XML
XSL
<xsl:choose>
<xsl:when test="#PARENT_OBH_ID">
<b><xsl:value-of select="#TITLE"/></b>
<xsl:for-each select="FOOTER">
-<xsl:value-of select="#TITLE"/>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</xsl:for-each>
Thanks
You're probably better off restructuring this to use templates, the system you're using at the moment means that the context data is becoming confused (you're xslt parser isn't sure which element it should read attributes from inside the second loop)
<xsl:choose>
<xsl:when test="#PARENT_OBH_ID">
<b><xsl:value-of select="#TITLE"/></b>
<xsl:apply-templates select="FOOTER" />
</xsl:when>
</xsl:choose>
<xsl:template match="FOOTER">
<xsl:value-of select="#TITLE"/>
</xsl:template>
apply-templates restarts the context with the footer element as the main focus (so #TITLE refers to the title attribute on footer, which is what you were aiming for I am guessing?)
Is it possible to add text from a xsl variable to the inside of a html tag something like this?
<xsl:variable name="selected">
<xsl:if test="#class = 'selected'"> class="selected"</xsl:if>
</xsl:variable>
<li{$selected}></li>
Try this:
<xsl:element name="li">
<xsl:if test="#class = 'selected'">
<xsl:attribute name="class">
selected
</xsl:attribute>
</xsl:if>
</xsl:element>
Optionally, the xsl:if could be nested in the xsl:attribute, instead of the other way around, if a class="" is desired. As already mentioned, it is unwise to write this as literal text.
You should not attempt to write this as literal text, instead look at xsl:element and xsl:attribute. Rough example:
<xsl:element name="li">
<xsl:attribute name="class">
<xsl:value-of select="$selected" />
</xsl:attribute>
</xsl:element>
Full documentation here.
Note that if you are careful enough to make it its first child, you can use <xsl:attribute> directly inside of your <li> tag, instead of using <xsl:element>
<li>
<xsl:if test="$selected">
<!-- Will refer to the last opened element, li -->
<xsl:attribute name="class">selected</xsl:attribute>
</xsl:if>
<!-- Anything else must come _after_ xsl:attribute -->
</li>