本文介绍了字符串中每个字母的XSLT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写XSLT转换(对于XSL-FO),并且需要为字符串值中的每个字母重复一些操作,例如:
$ b
如果字符串存储在 MyData / MyValue
字符串(例如MyData.MyValue =something),我需要一个for-每个像这样的:
< xsl:for-each select =MyData / MyValue> <! - 在这里迭代字母是什么? - >
< someTags>
< xsl:value-of select =Letter/> <! - 这里输出当前字母是什么? - >
< / someTags>
< / xsl:for-each>
有什么想法?
解决方案你可以使用一个调用模板并传递参数,然后使用递归来调用模板,直到没有字符。
示例添加如下。
关于这个xml
<?xml version =1.0 encoding =utf-8?>
< data>
< node>东西< / node>
< / data>
和这个xslt
<?xml version =1.0encoding =utf-8?>
xmlns:msxsl =urn:schemas-microsoft- com:xsltexclude-result-prefixes =msxsl
>
< xsl:output method =xmlindent =yes/>
< xsl:template match =data / node>
< xsl:with-param name =dataselect =。/>
< / xsl:call-template>
< / xsl:template>
< xsl:template name =for-each-character>
< xsl:param name =data/>
< xsl:if test =string-length($ data)& gt; 0>
< someTags>
< xsl:value-of select =substring($ data,1,1)/>
< / someTags>
< xsl:with-param name =dataselect =substring($ data,2)/>
< / xsl:call-template>
< / xsl:if>
< / xsl:template>
< / xsl:stylesheet>
然后你就可以在if语句中操作来做更多的事情了! b $ b
I'm writing an XSLT transformation (for XSL-FO), and need to repeat something for each letter in a string value, for example:
If string is stored in MyData/MyValue
string (e.g. MyData.MyValue = "something"), I need an for-each like this one:
<xsl:for-each select="MyData/MyValue"> <!-- What goes here to iterate through letters? -->
<someTags>
<xsl:value-of select="Letter" /> <!-- What goes here to output current letter? -->
</someTags>
</xsl:for-each>
Any ideas?
解决方案
you could use a call template and pass parameters, then use recursion to call the template untill there are no characters left.
example added below.
on this xml
<?xml version="1.0" encoding="utf-8"?>
<data>
<node>something</node>
</data>
and this xslt
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="data/node">
<xsl:call-template name="for-each-character">
<xsl:with-param name="data" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="for-each-character">
<xsl:param name="data"/>
<xsl:if test="string-length($data) > 0">
<someTags>
<xsl:value-of select="substring($data,1,1)"/>
</someTags>
<xsl:call-template name="for-each-character">
<xsl:with-param name="data" select="substring($data,2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
you will then be able to manipulate in the if statement to do further stuff!
这篇关于字符串中每个字母的XSLT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-18 22:34