And here is the solution:
<xsl:variable name="firstLine">
<xsl:value-of select="root/firstLine"/>
</xsl:variable>
That't how you get the value from the parameters (xml).
문제
I have an xsl file with variables and parameters. Parameters are defined in another xml file:
<fo:block><xsl:value-of select="root/period"/></fo:block>
and the parameter has the value:
<root>
<period>1-5</period>
</root>
Now, sometimes I want to display the block, containing the period, sometimes I don't. How can I achieve this? Here is how I tried:
<xsl:variable name="cond" select="root/cond"/>
<xsl:if test="$cond='1'">
<fo:block><xsl:value-of select="root/period"/></fo:block>
</xsl:if>
parameters:
<root>
<cond>1</cond>
<period>1-5</period>
</root>
This does not work!
I displayed the value of the variable using <xsl:copy-of select="$cond" />
and it's empty.
UPDATE:
I know now what the problem is:
xsl-fo:
<fo:flow flow-name="xsl-region-body">
<fo:block>
test
</fo:block>
<fo:block>
<xsl:variable name="cond" select=root/cond/>
<xsl:copy-of select="$cond" />
</fo:block>
<fo:block>
<xsl:value-of select="root/period"/>
</fo:block>
</fo:flow>
parameters:
<root>
<cond>haha</cond>
<period>01.01.2013 – 31.12.2013</period>
</root>
output:
test 01.01.2013 – 31.12.2013
So the question is really: how can I select a value from the xml parameters and assign the value to a xsl variable?
해결책 2
And here is the solution:
<xsl:variable name="firstLine">
<xsl:value-of select="root/firstLine"/>
</xsl:variable>
That't how you get the value from the parameters (xml).
다른 팁
A couple of things.
First of all, the updated XSL-FO you showed is not well-formed:
<xsl:variable name="cond" select=root/cond/>
The select attribute value needs quotes around it:
<xsl:variable name="cond" select="root/cond" />
I assume this is not really the problem, because if it were, you'd be getting no output at all, just an error.
But I think your real problem is where you say
<xsl:copy-of select="$cond" />
Since you are using copy-of instead of value-of, this copies the nodes in the $cond variable to the output. So your output FO will include the element <cond>haha</cond>
.
I don't know what an FO processor is supposed to do with elements like this that are in no namespace. Apparently, outputting the text content is not what it does; it probably ignores them.
Try changing that copy-of to value-of:
<xsl:value-of select="$cond" />
This will put haha
into the output, without the <cond>
element around it.
Try this, and if it doesn't do what you expect, tell us