how do you create an xml element attribute with a namespace

Discussion in 'XML' started by sqad, Oct 21, 2007.

  1. sqad

    sqad Guest

    <JiraJelly
    xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib">
    ....something
    </JiraJelly>

    Anyone know how to create this xml tag using the xsl:element? Having a
    problem with the "xmlns:jira" namespace part...parser hates that.

    Thanks,
    sqad
    sqad, Oct 21, 2007
    #1
    1. Advertising

  2. sqad wrote:
    > <JiraJelly
    > xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib">
    > ...something
    > </JiraJelly>
    >
    > Anyone know how to create this xml tag using the xsl:element?


    1) Why are you using xsl:element rather than a literal result element or
    xsl:copy, which are always simpler unless you need to calculate the
    element name?

    2) If you really must do so... Explicitly issuing namespace declaration
    nodes in specific places usingXSLT 1.0 is unfortunately rather awkward.
    You can't use xsl:attribute, since namespace declarations are not
    considered attributes by the XPath Data Model which XSLT is based on.
    About the only way I know of to do this is to copy the desired namespace
    node off a node that happens to carry that definition. (XSLT 2.0 fixes
    this by providing an explicit directive for the purpose, but there still
    aren't many processors available which support 2.0.)

    See some of the related discussion in
    http://www.dpawson.co.uk/xsl/sect2/N5536.html#d7594e1318

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Oct 21, 2007
    #2
    1. Advertising

  3. sqad

    sqad Guest

    On Oct 21, 1:26 pm, Joe Kesselman <> wrote:
    > sqad wrote:
    > > <JiraJelly
    > > xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib">
    > > ...something
    > > </JiraJelly>

    >
    > > Anyone know how to create this xml tag using the xsl:element?

    >
    > 1) Why are you using xsl:element rather than a literal result element or
    > xsl:copy, which are always simpler unless you need to calculate the
    > element name?
    >
    > 2) If you really must do so... Explicitly issuing namespace declaration
    > nodes in specific places usingXSLT 1.0 is unfortunately rather awkward.
    > You can't use xsl:attribute, since namespace declarations are not
    > considered attributes by the XPath Data Model which XSLT is based on.
    > About the only way I know of to do this is to copy the desired namespace
    > node off a node that happens to carry that definition. (XSLT 2.0 fixes
    > this by providing an explicit directive for the purpose, but there still
    > aren't many processors available which support 2.0.)
    >
    > See some of the related discussion inhttp://www.dpawson.co.uk/xsl/sect2/N5536.html#d7594e1318
    >
    > --
    > () ASCII Ribbon Campaign | Joe Kesselman
    > /\ Stamp out HTML e-mail! | System architexture and kinetic poetry


    Hi Joe,

    Thank you for your response.

    I tried all sort of hacks and realized QName can't contain namspace
    declarations. Unfortunately, the root node <JiraJelly> is not part of
    the xmlns:jira namespace. I just want to generate this tag in that
    exact syntax in the xml document following an xslt transformation.
    This is an xml document that's created after run via a XSLT 2.0
    parser. This is all done via Java, so if I can't run it via the
    transformer, I'll probably have to do this programatically - file
    open, string replace, file close...uber ugly solution

    /sqad
    sqad, Oct 21, 2007
    #3
  4. sqad wrote:
    > I tried all sort of hacks and realized QName can't contain namspace
    > declarations.


    You're still skipping direct to a proposed solution without giving us a
    chance to discuss what problem you're trying to solve or the context in
    which you're trying to solve it. That makes giving you useful advice
    EXTREMELY difficult.

    > Unfortunately, the root node <JiraJelly> is not part of
    > the xmlns:jira namespace.


    I don't follow why this is unfortunate...?

    > I just want to generate this tag in that
    > exact syntax in the xml document following an xslt transformation.


    If you're using XSLT 2.0, there is a directive which produces a
    namespace node on request. (Probably called xsl:namespace, but I may be
    misremembering that; check the spec or a good tutorial.)

    But again: Why can't you just use a literal result element, with a
    literal namespace declaration therein? Unless there's something you
    aren't telling us, it sounds like you're making the problem more
    difficult than it needs to be.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Oct 21, 2007
    #4
  5. sqad wrote:


    > > > <JiraJelly
    > > > xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib">
    > > > ...something
    > > > </JiraJelly>



    As has been said, why use xsl:element rather than something like
    <xsl:template match="whatever">
    <JiraJelly
    xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib">
    <xsl:apply-templates/>....
    </JiraJelly>
    </xsl:template>

    or more commonly, put the namespace declaration on the xsl:stylesheet
    element. the main reason for using xsl:element rather than this literal
    result syntax (apart from the ability to generate the element name
    dynamically) is that xsl:element _avoids_ copying namepsace nodes, which
    is exactly what you don't want to happen here.

    David

    --
    http://dpcarlisle.blogspot.com
    David Carlisle, Oct 22, 2007
    #5
    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. Replies:
    1
    Views:
    496
    George Bina
    Jul 20, 2006
  2. tankbattle
    Replies:
    1
    Views:
    772
    George Bina
    Jul 21, 2006
  3. anonymous
    Replies:
    1
    Views:
    5,903
  4. HANM
    Replies:
    2
    Views:
    684
    Joseph Kesselman
    Jan 29, 2008
  5. Iulian Ilea

    problem: create element in create element

    Iulian Ilea, Dec 14, 2006, in forum: Javascript
    Replies:
    4
    Views:
    172
    Iulian Ilea
    Dec 17, 2006
Loading...

Share This Page