List Info

Thread: getting text from external xml file




getting text from external xml file
user name
2007-07-31 04:42:10
Hi !

I would like to add on my titlepage a text (version number) coming from an external non docbook xml file.
In the facts : I use maven, so I have a pom.xml defining the version number of my project like this :

<;project xmlns="http://maven.apache.org/POM/4.0.0"
&nbsp; &nbsp; xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
 &nbsp;  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
&nbsp; &nbsp; <modelVersion>4.0.0</modelVersion&gt;

&nbsp; &nbsp; <name&gt;My Project<;/name>
 &nbsp;  <artifactId>my-project</artifactId>
&nbsp; &nbsp; <groupId>my.group</groupId>
&nbsp;   <version>1.5&lt;/version&gt;
&nbsp; &nbsp; [...]

I would like to get the value contained in <version> to add it dynamicaly on the titlepage, under my title (I've rewritten the book.titlepage.recto template in a xsl file).
Is there a way to do that ? in the xsl or directly in the docbook file, I could add it in the title or in the bookinfo section...

thanks in advance,
Marie.


Re: getting text from external xml file
user name
2007-07-31 04:49:58
Marie Sauvage - EBM WebSourcing wrote:
> Hi !
> 
> I would like to add on my titlepage a text (version
number) coming from an 
> external non docbook xml file.

Yes, can be done, but it may be easier to pass it in as a
parameter to 
the stylesheet?

If you want to modify the existing code it gets more
complex, simply
because it's on the title page?

Since you've done it, you know which stylesheet is used for
the 
titlepage generation? Not meant for modification is it,
being 
auto-generated.

You'll have to modify that to use the document('pom.xml')/
xpath to the 
version, after defining the namespace of course.

HTH


regards

-- 
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk


------------------------------------------------------------
---------
To unsubscribe, e-mail: docbook-apps-unsubscribelists.oasis-open.org
For additional commands, e-mail: docbook-apps-helplists.oasis-open.org


Re: getting text from external xml file
user name
2007-07-31 05:04:08
To pass it as a parameter would be easy for me, as I get it in my ant script before to call the generation !
How can I pass it as a parameter ?

But can you tell me more about the xpath solution ? or maybe give me a link to where to find doc about it ?
I think it could be better to have it directly in the stylesheet.

Regards,
Marie.


Dave Pawson a écrit :
dpawson.co.uk" type="cite">Marie Sauvage - EBM WebSourcing wrote:
Hi !

I would like to add on my titlepage a text (version number) coming from an external non docbook xml file.

Yes, can be done, but it may be easier to pass it in as a parameter to the stylesheet?

If you want to modify the existing code it gets more complex, simply
because it's on the title page?

Since you've done it, you know which stylesheet is used for the titlepage generation? Not meant for modification is it, being auto-generated.

You'll have to modify that to use the document('pom.xml')/ xpath to the version, after defining the namespace of course.

HTH


regards

Re: getting text from external xml file
user name
2007-07-31 05:21:19
Marie Sauvage - EBM WebSourcing wrote:
> To pass it as a parameter would be easy for me, as I
get it in my ant script 
> before to call the generation !
> How can I pass it as a parameter ?

 From the command line,

saxon inputFile.xml stylesheet.xsl date=2007-07031


> 
> But can you tell me more about the xpath solution ? or
maybe give me a link to 
> where to find doc about it ?
> I think it could be better to have it directly in the
stylesheet.

With the input file
<project xmlns="http://maven.
apache.org/POM/4.0.0"
     xmlnssi=&q
uot;http:
//www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache
.org/POM/4.0.0
ht
tp://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>

     <name>My Project</name>
     <artifactId>my-project</artifactId>
     <groupId>my.group</groupId>
     *<version>1.5</version>*

xmlns:ms="http://maven.
apache.org/POM/4.0.0"

It would be

<xsl:value-of
select="document('x.xml')/ms:project/ms:version"/&
gt;
if you wanted version
or
<xsl:value-of
select="document('x.xml')/ms:project/ms:ModelVersion&qu
ot;/>

to get 4.0.0



regards

-- 
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk


------------------------------------------------------------
---------
To unsubscribe, e-mail: docbook-apps-unsubscribelists.oasis-open.org
For additional commands, e-mail: docbook-apps-helplists.oasis-open.org


Re: getting text from external xml file
user name
2007-07-31 08:07:49
Great it works !

I did this in the ant build file to pass the pom file to the fo.xsl (I manage several projects, my task is dynamic) :
   ; <property name="pom" value="${basedir}/../${project.dir}/pom.xml" />
&nbsp; &nbsp; <xslt basedir="$" style="${style.file}"
 &nbsp;   ; &nbsp; &nbsp; in="tmpfile" out="${output}" extension="${extension}">
&nbsp;   ;  <param name="pomfile" expression="$" />
&nbsp; &nbsp;   [...]

Then, in my fo.xsl I add this to create the param :
  <xsl:param name="pomfile"><;/xsl:param>

and get the version in it as you said :
<xsl:value-of select="document($pomfile)/ms:project/ms:version"/>

thank you very much for your precious help !

Marie.

Dave Pawson a écrit :
dpawson.co.uk" type="cite">Marie Sauvage - EBM WebSourcing wrote:
To pass it as a parameter would be easy for me, as I get it in my ant script before to call the generation !
How can I pass it as a parameter ?

>From the command line,

saxon inputFile.xml stylesheet.xsl date=2007-07031



But can you tell me more about the xpath solution ? or maybe give me a link to where to find doc about it ?
I think it could be better to have it directly in the stylesheet.

With the input file
<project xmlns="http://maven.apache.org/POM/4.0.0"
 &nbsp;  xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
 &nbsp;  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd"&gt;
 &nbsp;  <modelVersion>4.0.0</modelVersion&gt;

 &nbsp;  <name&gt;My Project<;/name>
 &nbsp;  <artifactId>my-project</artifactId>
 &nbsp;  <groupId>my.group</groupId>
 &nbsp;  *<version>1.5&lt;/version&gt;*

xmlns:ms="http://maven.apache.org/POM/4.0.0"

It would be

<xsl:value-of select="document('x.xml')/ms:project/ms:version"/>
if you wanted version
or
<xsl:value-of select="document('x.xml')/ms:project/ms:ModelVersion"/&gt;

to get 4.0.0



regards

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )