Output first string, not all children's string

2019-09-02 17:54发布

问题:

I'm having an issue with a bit XSLT code I'm working with for a client. I cannot change the schema, as a flash application depends on it and making any changes would break the ActionScript. It's unfortunate.

This is my first foray into XSLT and I'm admittedly incompetant with it, so I was hoping the community could help me out.

This is the schema (XML file):

<statement title="Click on your Answer" answer="true">
   True or False: The question asked is here.
      <feedback>
         <answerTrue sound="">
            The response if the user answered true is here.
         </answerTrue>
         <answerFalse sound="">
            The response if the user answered false is here
         </answerFalse>
      </feedback>
</statement>

When I try to access the "statement" like this (XSLT):

<div id="statement">
 <xsl:value-of select="statement" />
</div>

It displays the "answerTrue" and "answerFalse" nodes along with it. I would like to only display the text "True or False: The ques...". If anyone knows of a tag I can use to display the statement without displaying the child elements, I'd be eternally grateful! Thanks!

回答1:

Use:

normalize-space(/statement/text()[1])


标签: xslt