Pergunta

I want to get the sub string of the text say 0-500 characters and then display an image and then again display the remaining part of the above text. I am getting 0-500 characters till the first full stop, using the below code :

  <xsl:value-of select="substring(metadata/item/body, 1, 500 + string-length(substring-before(substring(metadata/item/body, 501),'.')))" disable-output-escaping="yes"/>.

Then i am displaying the image.After which i am using this code to display the remaining part of text :

  <xsl:value-of select="substring(metadata/item/body, 500)" disable-output-escaping="yes"/>

Output which i am getting now :

  partnership with the private sector, especially the pharmaceutical sector.
  Image*****
  cal sector. He added that the future vision for the health....till end.

Expected output:

  partnership with the private sector, especially the pharmaceutical sector.
  Image*****
  He added that the future vision for the health....till end.
Foi útil?

Solução

In your code for the section before the image you are doing a wonderful job of finding the right place to break (which might not be at character 500. Then in the second piece of code rather than reuse that same method of finding where to start you are just starting at character 500. If you take the solution from the pre image part and use it for the post image part you'll get the output you are looking for.

Outras dicas

How about:

<xsl:variable name="stop" select="500 + string-length(substring-before(substring(input, 500),'.'))" />
<xsl:value-of select="substring(input, 1, $stop)"/>
<!-- image here -->
<xsl:value-of select="substring(input, $stop + 2 )"/>

Note: the + 2 is based on the assumption that there is a space or a line feed following the stop.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top