开发者

Delete first three & last four letters of XML using XSL

开发者 https://www.devze.com 2023-03-14 20:41 出处:网络
How can I delete (or exclude) the first three letters and last four letters of the \"admissionDescription\" XML string using XSL?

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消