xincluding a file twice

Discussion in 'XML' started by McSwell, Nov 30, 2008.

  1. McSwell

    McSwell Guest

    I want to xi:include (part of) a single XML file twice in the same XML
    document, and while it seems like it should be easy... well, that's
    always my experience with XML: the hard things it does easily, the
    simple things are what trip me up.

    The file to be included is named fragUnicodePhonemes.xml, and it looks
    like this:
    ---------------------------------
    <?xml version="1.0" encoding="utf-8"?>
    <src:fragment xml:id = "fragUnicodePhonemes"
    xmlns:src = "http://docbook.sourceforge.net/release/
    litprog/current/dtd/ldocbook.dtd"
    (other namespace declarations here)
    >


    <Ph:phonemeSet xml:id = "UrduPhonemeSet)">
    (lots of messy stuff here)
    </Ph:phonemeSet>

    </src:fragment>
    ---------------------------------
    As you may guess, I'm using an <src:fragment> Literate Programming
    construct, shamelessly stolen and modified to work with DocBook 5.

    I want to embed the above <Ph:phonemeSet> in two different places (one
    happens to be an appendix, which maybe explains the redundancy). One
    time the entire <src:fragment> gets embedded (so it can be extracted
    using the Lit Prog style sheet):
    <xi:include href="fragUnicodePhonemes.xml"
    xpointer="element(fragUnicodePhonemes)" />
    The other time only the <Ph:phonemeSet> gets embedded:
    <xi:include href="fragUnicodePhonemes.xml"
    xpointer="element(UrduPhonemeSet)" />
    The problem is that the <Ph:phonemeSet xml:id = "UrduPhonemeSet)">
    element gets embedded both times (once inside the <src:fragment>, and
    once by itself)--and so its xml:id shows up twice, which means it
    flunks validation (xsltproc complains).

    If I could get it to omit the xml:id when it embeds the element, I
    guess it would be fine (the only use of the id is to "find" the
    element in the external file so it can be embedded, although I suppose
    it could end up being used for something else). Or maybe I should
    just ignore the warning, taking Mad Magazine's advice: What, me
    worry? Or maybe I should change the '<' and '>' to '&lt;' and '&gt;'
    before embedding them, although that feels like a kludge. Or maybe I
    should just reference the first occurrence in the appendix, instead of
    a including it a second time; but that would be more obscure than I
    would like. Or maybe there's a way to define it as an entity...

    Suggestions?

    Mike Maxwell
    CASL/ U MD
     
    McSwell, Nov 30, 2008
    #1
    1. Advertising

  2. McSwell wrote:
    > I want to xi:include (part of) a single XML file twice in the same XML
    > document


    --snip--

    > The problem is that the <Ph:phonemeSet xml:id = "UrduPhonemeSet)">
    > element gets embedded both times (once inside the <src:fragment>, and
    > once by itself)--and so its xml:id shows up twice, which means it
    > flunks validation (xsltproc complains).


    Since you are using xsltproc you can use the xpointer() scheme. See
    here: http://www.sagehill.net/docbookxsl/DuplicateIDs.html


    // Magnus
     
    Magnus Henriksson, Dec 3, 2008
    #2
    1. Advertising

  3. McSwell

    McSwell Guest

    On Dec 3, 6:28 am, Magnus Henriksson
    <> wrote:
    > Since you are using xsltproc you can use the xpointer() scheme. See
    > here:http://www.sagehill.net/docbookxsl/DuplicateIDs.html


    Thanks, that was exactly what I needed! (It took me awhile to figure
    out the syntax for the namespace
    names, but I found an example here: http://www.w3.org/TR/xptr-xmlns/.
    That's maybe the first time
    I've been able to understand a W3C spec well enough to use it. I
    guess there's hope for me yet :).)

    Mike Maxwell
     
    McSwell, Dec 5, 2008
    #3
    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. khawar
    Replies:
    1
    Views:
    476
    AlexS
    Jul 15, 2003
  2. ben
    Replies:
    0
    Views:
    1,071
  3. Jeremy Bishop

    c++ file i/o: cant use file twice

    Jeremy Bishop, Nov 13, 2003, in forum: C++
    Replies:
    2
    Views:
    579
    amit gulati
    Nov 13, 2003
  4. Kiuhnm

    twice(twice(x))

    Kiuhnm, Apr 1, 2006, in forum: C++
    Replies:
    2
    Views:
    402
    Kiuhnm
    Apr 1, 2006
  5. mike
    Replies:
    3
    Views:
    162
Loading...

Share This Page