Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a xml like this,
<doc>
<para>A brief 23 spell$of hea#vy rain$forc^%ed an early+ lunch$98#with nine</para>
</doc>
I need to break the text string from each $ present in the text.
SO expected output should be,
<doc>
<para>A brief 23 spell</para>
<para>of hea#vy rain</para>
<para>forc^%ed an early+ lunch</para>
<para>98#with nine</para>
</doc>
Can anyone suggest to me how can I do this using XSLT 1.0?
Try this
<xsl:template match="para">
<xsl:call-template name="spilit">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="spilit">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '$')">
<para><xsl:value-of select="substring-before($text, '$')"/></para>
<xsl:call-template name="spilit">
<xsl:with-param name="text" select="substring-after($text, '$')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<para><xsl:value-of select="$text"/></para>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
See Transformation at https://xsltfiddle.liberty-development.net/bEJbVrg
Related
I have a little problem and I just can't seem to figure it out. I have a RTF string in an XML and want to cut out images there. That works so far. But now I have the problem that the string is only checked and shortened once. But there can be between 0 and infinite images attached. I do not understand how I can replace all of them, i.e. execute concat several times.
Thanks so much for your help
XML File:
https://pastebin.com/6iVuFasn
My XSL Code:
<xsl:variable name="storyFormattedText" select="//STORY_TEXT_RTF"/>
<xsl:variable name="textWithoutImages">
<xsl:value-of select="$storyFormattedText"/>
<xsl:if test="contains($storyFormattedText,'{\result{\pict{\*\picprop}')">
<xsl:value-of select="concat(substring-before($storyFormattedText,'{\result{\pict{\*\picprop}'),substring-after($storyFormattedText,'}}}'))"/>
</xsl:if>
</xsl:variable>
<xsl:call-template name="create_field">
<xsl:with-param name="field_id">15</xsl:with-param>
<xsl:with-param name="field_type">1</xsl:with-param>
<xsl:with-param name="field_name">Formatted Text ohne Bilder</xsl:with-param>
<xsl:with-param name="is_empty">no</xsl:with-param>
<xsl:with-param name="value">
<xsl:value-of select="concat(substring-before($storyFormattedText,'{\result{\pict{\*\picprop}'),substring-after($storyFormattedText,'}}}'))"/>
</xsl:with-param>
</xsl:call-template>
I found this piece of code which wraps the data inside a cell ,but it doesn't take into account the word i.e if the complete word cannot be fitted in the line ,It doesn't change the line .It writes few alphabets before changing the line .
What should I modify in this code so that If a particular word is not getting adjusted in the line , it changes the line .
Also , I am new to xsl -fo .I have understood most of the code ,but would appreciate if a little could be explained .
<xsl:template name="zero_width_space_1">
<xsl:param name="data"/>
<xsl:param name="counter" select="0"/>
<xsl:choose>
<xsl:when test="$counter < string-length($data)">
<xsl:value-of select='concat(substring($data,$counter,1),"")'/>
<xsl:call-template name="zero_width_space_2">
<xsl:with-param name="data" select="$data"/>
<xsl:with-param name="counter" select="$counter+1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="zero_width_space_2">
<xsl:param name="data"/>
<xsl:param name="counter"/>
<xsl:value-of select='concat(substring($data,$counter,1),"")'/>
<xsl:call-template name="zero_width_space_1">
<xsl:with-param name="data" select="$data"/>
<xsl:with-param name="counter" select="$counter+1"/>
</xsl:call-template>
</xsl:template>
and then placing a call to zero_width_space_1 like following-
<xsl:call-template name="zero_width_space_1">
<xsl:with-param name="data" select="span"/>
</xsl:call-template>
for ex - "I found this piece of code which wraps the data inside a cell "..It shows as in a cell as
I found th
is piece o
f code whi
ch wraps t
he data in
side a cel
l
Wrapping is provided by the cells automatically . Zero_width_space includes a zero-width space after every character ,so better to not call this template if the requirement is not filling the cells character wise .
I am writing my thesis and my professor wants me to use the APA style. Here I have the problem, that it shows dates like this "DD. MM YYYY" However, I want it to be "DD.MM.YYYY".
Somehow it not only uses spaces in general, there is this single dot after the date. This means it is not a style I dont generylly like, but it seems to be buggy. Why?
I have looked through the xls file but just cannot find the exact problem. In the Harvard xml, it was easy because i just needed to change "spaces" to "dot"-templates. Here, however, they seem to use a recursive style and I have no clue, where I need to make changes.
I would very grateful if anyone could help me!
I use office365, and I tried changing the xls I found at C:\Users\$user\AppData\Roaming\Microsoft\Bibliography\Style\APASixthEditionOfficeOnline.xsl
Here (pastebin) is the original code from the part, where I believe the "spaces" and "dots" are put.
the parameters are:
format: which is either MY or DMY (depending if day field is put or not)
day, month and year: are the data of the souce
withDot is initially not set (at least I cant find it anywhere)
I you need any further information, please let me know.
UPDATE
Here is the complete bibliography style code from Windows.
Here is the selected code with all templates that I believe are called while formatting the date(s).
It's not possible to reproduce the problem from what you posted, mainly because the template you refer to requires other templates.
In any case, if all you need is to produce two different formats of date, you could do this much more simply by:
<xsl:template name="formatDate">
<xsl:param name="day"/>
<xsl:param name="month"/>
<xsl:param name="year"/>
<xsl:param name="format" />
<xsl:choose>
<xsl:when test="$format='DMY'">
<xsl:value-of select="format-number($day, '00.')"/>
<xsl:value-of select="format-number($month, '00.')"/>
<xsl:value-of select="$year"/>
</xsl:when>
<xsl:when test="$format='MY'">
<xsl:value-of select="format-number($month, '00.')"/>
<xsl:value-of select="$year"/>
</xsl:when>
<xsl:otherwise>??</xsl:otherwise>
</xsl:choose>
</xsl:template>
Examples of calling the template:
call:
<date>
<xsl:call-template name="formatDate">
<xsl:with-param name="format" select="'DMY'"/>
<xsl:with-param name="day" select="5"/>
<xsl:with-param name="month" select="3"/>
<xsl:with-param name="year" select="2014"/>
</xsl:call-template>
</date>
returns:
<date>05.03.2014</date>
call:
<date>
<xsl:call-template name="formatDate">
<xsl:with-param name="format" select="'MY'"/>
<xsl:with-param name="month" select="7"/>
<xsl:with-param name="year" select="1876"/>
</xsl:call-template>
</date>
returns:
<date>07.1876</date>
This is my XML:
<AUDITDATA>
<USERS>
<Domain>DOMAUDIT</Domain>
<UserName>Aashu</UserName>
<PassWord>m0eYN2VM</PassWord>
<Description>1234</Description>
<UserType>AdminOps</UserType>
<UserRoles.Painter>YES</UserRoles.Painter>
<UserRoles.Driver>NO</UserRoles.Driver>
<UserRoles.Cook>YES</UserRoles.Cook>
<!-- like this there may be more roles also.-->
</USERS>
</AUDITDATA>
For XML Tags apart from "UserRoles.*" I have wriiten XSL code lyke this:
<xsl:template name="Users">
<xsl:call-template name="FormatTextData">
<xsl:with-param name="textValue" select="//UserName"/>
<xsl:with-param name="displayValue" select="'User Name='"/>
</xsl:call-template>
<xsl:call-template name="FormatTextData">
<xsl:with-param name="textValue" select="//PassWord"/>
<xsl:with-param name="displayValue" select="',Password='"/>
</xsl:call-template>
<xsl:call-template name="FormatTextData">
<xsl:with-param name="textValue" select="//Description"/>
<xsl:with-param name="displayValue" select="',Description='"/>
</xsl:call-template>
<xsl:call-template name="FormatTextData">
<xsl:with-param name="textValue" select="//UserType"/>
<xsl:with-param name="displayValue" select="',User Type='"/>
</xsl:call-template>
</xsl:template>
And this is working fine for others tags, how to write for UserRoles tags, as you can see the no of Roles are not fixed, I want to tackel all roles via one block of code in XSL file.
The Problem is, how to define a XSL for XML tags, whose TagName is not static, or only a part is static.
Please help
I don't really follow your XSL, but you can select all the UserRoles.* elements by:
select="AUDITDATA/USERS/*[starts-with(name(), 'UserRoles.')]"
Can anyone tell me how to select the URL from this:
<media:content url="http://feedproxy.google.com/~r/TEDTalks_video/~5/aZWq6PY05YE/TimBrown_2009G.mp4" fileSize="57985745" type="video/mp4" />
I want to:
Create a link to this file:
Trim the URL from:
http://feedproxy.google.com/~r/TEDTalks_video/~5/aZWq6PY05YE/TimBrown_2009G.mp4
to:
TimBrown_2009G
and then take: TimBrown_2009G and use it as part of a URL
Selecting the URL. You just need to make sure that you have the correct namespace URI.
<xsl:value-of xmlns:media="http://search.yahoo.com/mrss/"
select="media:content/#url"/>
Trimming down the URL. How to do this best depends on whether you are using XSLT 1 or 2, since the latter has better string handling functions from XPath 2.0.
If you are using XSLT 1, you might want to create a helper template to return the last segment out of a delimited string:
<xsl:template name="last-substring-after">
<xsl:param name="string"/>
<xsl:param name="separator"/>
<xsl:choose>
<xsl:when test="contains($string, $separator)">
<xsl:call-template name="last-substring-after">
<xsl:with-param name="string"
select="substring-after($string, $separator)"/>
<xsl:with-param name="separator"
select="$separator"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Then you can make use of that to extract the last segment of the URL, and proceed to extract the part before the dot. Assuming the URL is in variable url:
<xsl:variable name="name">
<xsl:call-template name="last-substring-after">
<xsl:with-param name="string" select="$url"/>
<xsl:with-param name="separator" select="'/'"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="substring-before($name, '.')"/>