I'm having trouble generating a dynamic message using Barcode4J ean-13 in an Apache FOP xsl document. I did get the barcode to generate using a hard coded message. However, I would like to pass the barcode number to the xsl document as a parameter. How do I go about doing that?
Also, I have referred to the barcode4J site for help page with no luck. I have tried using the technique described here but had no luck.
This is how my xsl document looks like
<fo:block-container left="1000" top="1000"
z-index="1" position="relative">
<fo:block>
<fo:instream-foreign-object>
<bc:barcode xmlns:bc="http://barcode4j.krysalis.org/ns"
message="123456789789">
<bc:ean-13 />
</bc:barcode>
</fo:instream-foreign-object>
</fo:block>
</fo:block-container>
You don't say which XSLT version you are using.
If you want to pass a parameter to your XSLT, you need to declare the parameter as a child element of your xsl:stylesheet
, e.g.:
<xsl:param name="barcode" />
For XSLT 1.0, see http://www.w3.org/TR/xslt#top-level-variables. You could declare more about it if you are using XSLT 2.0.
How to pass the parameter value will depend on which XSLT processor you are using, but you can expect that to be covered in the XSLT processor's documentation.
You can then use the $barcode
parameter in an 'attribute value template' in your otherwise-literal markup:
<fo:block-container left="1000" top="1000"
z-index="1" position="relative">
<fo:block>
<fo:instream-foreign-object>
<bc:barcode xmlns:bc="http://barcode4j.krysalis.org/ns"
message="{$barcode}">
<bc:ean-13 />
</bc:barcode>
</fo:instream-foreign-object>
</fo:block>
</fo:block-container>
For attribute value templates in XSLT 1.0, see http://www.w3.org/TR/xslt#dt-attribute-value-template