how to output unresolved xinclude element

Discussion in 'XML' started by shaun roe, Mar 7, 2007.

  1. shaun roe

    shaun roe Guest

    I should like to use xslt to produce a document like the following:

    <crate xmlns:xi="http://www.w3.org/2001/XInclude">
    <rod id="0">
    <slot>1</slot>
    <xi:include href="./endcapA/disk/1a/10011.xml"/> <!--D1A TR
    middles-->
    <xi:include href="./endcapA/disk/1a/10012.xml"/> <!--D1A TR
    middles-->
    <xi:include href="./endcapA/disk/1a/10001.xml"/> <!--D1A TR
    outers-->
    <xi:include href="./endcapA/disk/1a/10002.xml"/> <!--D1A TR
    outers-->
    <xi:include href="./endcapA/disk/2a/20001.xml"/> <!--D2A TR
    outers-->
    <xi:include href="./endcapA/disk/2a/20002.xml"/> <!--D2A TR
    outers-->
    <xi:include href="./endcapA/disk/3a/30001.xml"/> <!--D3A TR
    outers-->
    <xi:include href="./endcapA/disk/3a/30002.xml"/> <!--D3A TR
    outers-->
    </rod>
    </crate>

    i.e. it should contain 'manufactured' unresolved xi:include elements.
    How can I get my xsl to output such an element?

    thanks

    shaun
    shaun roe, Mar 7, 2007
    #1
    1. Advertising

  2. > i.e. it should contain 'manufactured' unresolved xi:include elements.
    > How can I get my xsl to output such an element?


    The simplest answer: http://www.w3.org/TR/xslt#element-namespace-alias

    An alternative is to construct the element explicitly using the
    xsl:element directive.

    Either will prevent the new element from being prematurely interpreted.

    (These tricks are more often used when writing stylesheets that produce
    stylesheets, but they're certainly applicable to this problem as well.)

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Mar 7, 2007
    #2
    1. Advertising

  3. shaun roe

    shaun roe Guest

    The namespace-alias seems neat, but I get a bit of ugliness with it:

    I declare my namespaces:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude"
    xmlns:xout="myAlias">

    and my alias:

    <xsl:namespace-alias stylesheet-prefix="xout" result-prefix="xi"/>

    and then use it...

    <xout:include href="concat($MurPathRoot,$diskpath,'/',xmlMur) "/>


    and sure enough all my elements come out ok:

    <xout:include href="./endcapA/disk/1a/10301"/>


    but the root document element is:

    <configuration xmlns:xi="http://www.w3.org/2001/XInclude"
    xmlns:xout="http://www.w3.org/2001/XInclude">

    i.e. its declared both the original xi: and my xout: ... is this
    expected?

    thanks

    shaun



    In article <45eee4de$1@kcnews01>,
    Joseph Kesselman <> wrote:

    > http://www.w3.org/TR/xslt#element-namespace-alias
    shaun roe, Mar 7, 2007
    #3
  4. shaun roe wrote:
    > i.e. its declared both the original xi: and my xout: ... is this
    > expected?


    There's a similar directive which lets you suppress namespace
    declarations that aren't in use. See the spec and/or Kay's book, or wait
    a few hours for me to get around to looking it up.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Mar 7, 2007
    #4
  5. Joseph Kesselman wrote:
    > There's a similar directive which lets you suppress namespace
    > declarations that aren't in use. See the spec and/or Kay's book, or wait
    > a few hours for me to get around to looking it up.


    Since you waited: What you want is the exclude-result-prefixes attribute
    of the xsl:stylesheet element. It's described in
    http://www.w3.org/TR/xslt#section-Creating-Elements-and-Attributes

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Mar 8, 2007
    #5
  6. In article <>,
    Joe Kesselman <> wrote:

    >> There's a similar directive which lets you suppress namespace
    >> declarations that aren't in use. See the spec and/or Kay's book, or wait
    >> a few hours for me to get around to looking it up.


    >Since you waited: What you want is the exclude-result-prefixes attribute
    >of the xsl:stylesheet element. It's described in
    >http://www.w3.org/TR/xslt#section-Creating-Elements-and-Attributes


    I think this won't necessarily do quite the right thing in this case.
    Despite its name, exclude-result-prefixes specifies a namespace uri to
    be excluded, not a prefix. Since in this case he does need the
    xinclude namespace, he may well still get a spurious xout prefix
    declared somewhere.

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
    Richard Tobin, Mar 8, 2007
    #6
  7. Richard Tobin wrote:
    > I think this won't necessarily do quite the right thing in this case.
    > Despite its name, exclude-result-prefixes specifies a namespace uri to
    > be excluded, not a prefix. Since in this case he does need the
    > xinclude namespace, he may well still get a spurious xout prefix
    > declared somewhere.


    In the implementation I'm familiar with (Xalan), it should do the right
    thing, because it's take as a request not to issue any declarations for
    prefixes bound to that URI except those which are actually used by an
    element or attribute. But while that's a reasonable interpretation It
    may not be the only one... Best suggestion I can make is to try it and
    see what happens.

    If it doesn't work -- well, an unused namespace declaration really is
    pretty harmless.


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Mar 8, 2007
    #7
  8. shaun roe

    shaun roe Guest

    In article <>,
    Joe Kesselman <> wrote:

    > Richard Tobin wrote:
    > > I think this won't necessarily do quite the right thing in this case.
    > > Despite its name, exclude-result-prefixes specifies a namespace uri to
    > > be excluded, not a prefix. Since in this case he does need the
    > > xinclude namespace, he may well still get a spurious xout prefix
    > > declared somewhere.

    >
    > In the implementation I'm familiar with (Xalan), it should do the right
    > thing, because it's take as a request not to issue any declarations for
    > prefixes bound to that URI except those which are actually used by an
    > element or attribute. But while that's a reasonable interpretation It
    > may not be the only one... Best suggestion I can make is to try it and
    > see what happens.
    >
    > If it doesn't work -- well, an unused namespace declaration really is
    > pretty harmless.


    I did indeed try this as a first move, and as Richard Tobin has said, it
    did not suppress the declaration. (using Saxon) I can live with two
    declarations of the namespace, its just not as neat as I'd hoped.

    In fact, give that both namespaces are declared anyway in the output, I
    found I can reverse the alias/output assignation:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" xmlns:x="http://www.w3.org/2001/XInclude"
    xmlns:xi="myAlias">

    ..
    ..
    ..

    <xi:include href="concat($MurPathRoot,$diskpath,'/',xmlMur) "/>


    and get, as output:

    <configuration xmlns:x="http://www.w3.org/2001/XInclude"
    xmlns:xi="http://www.w3.org/2001/XInclude">
    ..
    ..
    ..
    ..
    <xi:include href="./endcapA/disk/2a/20302"/>


    which leaves my end users looking at the familiar <xi:include .../>,
    which I suspect they will be happier with.

    thanks for the help

    shaun
    shaun roe, Mar 8, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ed Dennison
    Replies:
    0
    Views:
    460
    Ed Dennison
    Sep 12, 2003
  2. Erdem Guven

    XInclude

    Erdem Guven, Aug 12, 2004, in forum: XML
    Replies:
    1
    Views:
    600
    Matthias Jung
    Aug 12, 2004
  3. CB
    Replies:
    1
    Views:
    546
    Igor Zlatkovic
    Aug 25, 2004
  4. SL
    Replies:
    0
    Views:
    519
  5. tsterkel
    Replies:
    0
    Views:
    490
    tsterkel
    Apr 25, 2005
Loading...

Share This Page