docbook-apps

  • 1.  getting text from external xml file

    Posted 07-31-2007 09:42
    
    
      
    
    
    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"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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>
        [...]

    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.




  • 2.  Re: [docbook-apps] getting text from external xml file

    Posted 07-31-2007 09:50
    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



  • 3.  Re: [docbook-apps] getting text from external xml file

    Posted 07-31-2007 10:04
    
    
      
    
    
    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 :
    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



  • 4.  Re: [docbook-apps] getting text from external xml file

    Posted 07-31-2007 10:21
    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"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
    http://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"/>
    if you wanted version
    or
    <xsl:value-of select="document('x.xml')/ms:project/ms:ModelVersion"/>

    to get 4.0.0



    regards

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



  • 5.  Re: [docbook-apps] getting text from external xml file

    Posted 07-31-2007 13:08
    
    
      
    
    
    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" />
        <xslt basedir="${basedir}" style="${style.file}"
              in="tmpfile" out="${output}" extension="${extension}">
          <param name="pomfile" expression="${pom}" />
          [...]

    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 :
    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"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
    http://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"/>
    if you wanted version
    or
    <xsl:value-of select="document('x.xml')/ms:project/ms:ModelVersion"/>

    to get 4.0.0



    regards