Generate XML output to a fitting format to match my XSLT
Hey, I am writing a quiz application with Java Servlets. My quiz data is written into XML files, i.e.: <quiz><question><ask>...</ask><answer>...</answer>...</question></quiz>
.
I want to display every question and their answers on a single page. For that reason, I cannot simply transform the XML to my XSLT as it开发者_JAVA百科 would display only the first question or all questions. My guess is, I should load the XML data in order to create my own Java classes, i.e.: class Question, class Quiz, etc and generate from them a XML format which fits my XSLT displaying only one question at a time.
Is this approach the right way and if so, how is this realized?
If not, how is it done probably?
I cannot simply transform the XML to my XSLT as it would display only the first question or all questions.
You are wrong. If you write your XSLT using templates and the correct XPath, a transform could output all of the questions that exist in one XML file, however many.
You can also use XPath to select specific question
nodes, depending on attribute values (for example).
If you have the following template and use the right XPath to select all questions in an apply-templates
, this template will be applied to each question, not just the first:
<xsl:template match="question">
</xsl:template>
精彩评论