How can I delete (or exclude) the first three letters and last four letters of the "admissionDescription" XML string using XSL?
Here's my page, XML and code:
<xsl:if test="cost | admissionDescription">
<dt>Admission:</dt>
<dd>
<xsl:if test="cost"><xsl:value-of select="cost"/><br/></xsl:if>
<xsl开发者_开发知识库:if test="admissionDescription"><xsl:value-of select="admissionDescription" disable-output-escaping="yes"/></xsl:if>
</dd>
</xsl:if>
You can use the XPath functions substring
and string-length
. Here is a simple reference http://www.w3schools.com/xpath/xpath_functions.asp#string
Update
You don't need the fn
prefix. Here is an example
substring(admissionDescription,4,string-length(admissionDescription)-7)
Given this test input
<xml>
<cost>5</cost>
<admissionDescription>123sometext4321</admissionDescription>
</xml>
Applying your XSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="xml">
<xsl:copy>
<xsl:if test="cost | admissionDescription">
<dt>Admission:</dt>
<dd>
<xsl:if test="cost"><xsl:value-of select="cost"/><br/></xsl:if>
<xsl:if test="admissionDescription"><xsl:value-of select="substring(admissionDescription,4,string-length(admissionDescription)-7)" disable-output-escaping="yes"/></xsl:if>
</dd>
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
you get the desired output
<xml>
<dt>Admission:</dt>
<dd>5
<br/>sometext</dd>
</xml>
精彩评论