XSLT Atrtibute Value

Discussion in 'XML' started by parvus, Jan 11, 2006.

  1. parvus

    parvus Guest

    Hi, I´m searching a solution for the following problem:
    I´ve a generated XML Document like

    <....>
    <struct name="number" type="PartNumber">100</struct>
    <struct name="identity" type="PartIdentity">1</struct>
    <enum name="ex_identity" type="....."></enum>
    <....>

    Now i want to use a XSLT file to create a new structured XML file like

    <....>
    <number sort="struct" type="PartNumber">100</struct>
    <identity sort="struct" type="PartIdentity">1</struct>
    <ex_identity sort="enum" type="........

    My problem ist, that i couldn´t read out the value of the attribute
    "name" so i can´t
    create a new element of it. Furthermore i need to create the other
    attributes for the new element or maybe i can copy them easily(?). Does
    anybody have any solution? PLZ help me im searching for a long time.

    Big THX parvus
    parvus, Jan 11, 2006
    #1
    1. Advertising

  2. parvus wrote:
    [...]
    > Now i want to use a XSLT file to create a new structured XML file like
    >
    > <....>
    > <number sort="struct" type="PartNumber">100</struct>
    > <identity sort="struct" type="PartIdentity">1</struct>
    > <ex_identity sort="enum" type="........

    [...]
    Using enum is a good idea. But the above is not well formed XML.
    Maybe you want something else?
    Edwin Kapauni, Jan 11, 2006
    #2
    1. Advertising

  3. In article <>,
    parvus <> wrote:

    ><struct name="number" type="PartNumber">100</struct>


    ><number sort="struct" type="PartNumber">100</struct>


    You want something like

    <xsl:element name="{@name}"> ...

    -- Richard
    Richard Tobin, Jan 11, 2006
    #3
  4. parvus

    parvus Guest

    Big THX for these very fast answers, but

    <xsl:element name="{@name}"> ...

    doesn´t work thats the problem. Furthermore with "{@name}" i don´t
    get the value but the name of the attribute. I need the value. I
    searched on www.w3.org but i didn´t find any solution.
    parvus, Jan 11, 2006
    #4
  5. parvus

    Soren Kuula Guest

    Hi,
    > Hi, I´m searching a solution for the following problem:
    > I´ve a generated XML Document like
    >
    > <....>
    > <struct name="number" type="PartNumber">100</struct>
    > <struct name="identity" type="PartIdentity">1</struct>
    > <enum name="ex_identity" type="....."></enum>
    > <....>
    >
    > Now i want to use a XSLT file to create a new structured XML file like
    >
    > <....>
    > <number sort="struct" type="PartNumber">100</struct>
    > <identity sort="struct" type="PartIdentity">1</struct>
    > <ex_identity sort="enum" type="........
    >
    > My problem ist, that i couldn´t read out the value of the attribute
    > "name" so i can´t
    > create a new element of it.


    Why couldn't you? Does <element name="{@name}"/> not work?

    Furthermore i need to create the other
    > attributes for the new element or maybe i can copy them easily(?). Does
    > anybody have any solution? PLZ help me im searching for a long time.


    <attribute name="sort"><value-of select="local-name()"/></attribute>

    Soren
    Soren Kuula, Jan 11, 2006
    #5
  6. In article <>,
    parvus <> wrote:

    ><xsl:element name="{@name}"> ...
    >
    >doesn't work


    > Furthermore with "{@name}" i don´t
    >get the value but the name of the attribute. I need the value.


    It gives you the value of the attribute. So there must be something
    wrong with your version of it, or the stylesheet processor you're using.
    You need to give us a complete stylesheet that shows the problem
    if you want more help.

    -- Richard
    Richard Tobin, Jan 11, 2006
    #6
  7. parvus

    parvus Guest

    Ok THX Richard Tobin, now I think its really a problem of my stylesheet
    processor. Which processor do you use? Im using this M$ IEXMLTLS.
    parvus, Jan 11, 2006
    #7
  8. parvus

    Soren Kuula Guest

    parvus wrote:
    > Big THX for these very fast answers, but
    >
    > <xsl:element name="{@name}"> ...
    >
    > doesn´t work thats the problem. Furthermore with "{@name}" i don´t
    > get the value but the name of the attribute. I need the value. I
    > searched on www.w3.org but i didn´t find any solution.


    Sure you did not write {name()} ??

    Soren
    Soren Kuula, Jan 11, 2006
    #8
  9. parvus

    parvus Guest

    So i post my XML and XSLT File maybe you´ll find the mistake:
    XML:
    -------

    <?xml version="1.0" encoding="iso-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="rdm.xslt"?>

    <any>
    <struct name="identity" type="IDM:RDM/Track:1.0">100</struct>
    <struct name="strength" type="IDM:RDM/TrackStrength:1.0">200</struct>
    <string name="test"></string>
    </any>

    XSLT:
    --------

    <?xml version="1.0" encoding="iso-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="xml" indent="yes"/>

    <xsl:template match="/">
    <any>
    <xsl:apply-templates/>
    </any>
    </xsl:template>

    <xsl:template match="any/struct[1]">
    <xsl:for-each select="@name">
    <xsl:element name="{@name}">
    <xsl:value-of select="."/>
    </xsl:element>
    </xsl:for-each>
    </xsl:template>
    .............

    With this XSLT my Browser IE 6.0.2800.1106 replys:
    "Um Knoten vom Typ 'ELEMENT' zu erstellen, muss ein gültiger Name
    angegeben werden."

    That means:
    "When you want to create nodes type ELEMENT you should enter a valid
    name"
    parvus, Jan 12, 2006
    #9
  10. parvus

    parvus Guest

    Oh dear what a mistake :-(. BIG BIG BIG THX!!! It works. I think it was
    a bad Newbie Mistake. Really THX!
    parvus, Jan 12, 2006
    #10
  11. parvus

    Soren Kuula Guest

    parvus wrote:
    > So i post my XML and XSLT File maybe you´ll find the mistake:
    > XML:


    > <?xml version="1.0" encoding="iso-8859-1"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:eek:utput method="xml" indent="yes"/>
    >
    > <xsl:template match="any/struct[1]">
    > <xsl:for-each select="@name">


    Now you iterate over each name attribute of the first struct child of
    any any element.... there's only one of those attributes of course

    > <xsl:element name="{@name}">


    Now you try to take the value of the name attribute of the context node
    .... which is the name attribute. In other words, you are selecting the
    name atttribute of the name attribute ... there is none ;)

    > <xsl:value-of select="."/>
    > </xsl:element>
    > </xsl:for-each>
    > </xsl:template>


    Instead try:
    <xsl:template match="any/struct">
    <xsl:element name="{@name}">
    <xsl:value-of select="."/>
    </xsl:element>
    </xsl:template>

    OR

    <xsl:template match="any/struct">
    <xsl:for-each select="@name">
    <xsl:element name="{.}">
    <xsl:value-of select="."/>
    </xsl:element>
    </xsl:for-each>
    </xsl:template>

    (there's a difference). I think you want the first one (the second one
    produces rather boring results, try it!! And using for-each over named
    attributes is an unusual thing to do, since there is at most one anyway).


    Soren
    Soren Kuula, Jan 12, 2006
    #11
  12. parvus

    parvus Guest

    It works nice one. Another Question is how im able to make a break
    after each Element?
    Now my XSLT produce a file like:

    "<?xml version="1.0" encoding="UTF-16"?><any><struct
    type="IDL:RDM/Track:1.0"><id format="ulong">1</id><number
    format="ulong">100</number></struct></any>"

    Can i somehow control that my document becomes:

    <?xml version="1.0" encoding="UTF-16"?>
    <any>
    <struct type="Part/Track">
    <id format="ulong">1</id>
    <number format="ulong">100</number>
    </struct>
    </any>

    You know what i mean?! THX
    parvus, Jan 12, 2006
    #12
  13. parvus

    parvus Guest

    It works without problems. But how can I copy the second attrivute?!
    Its no problem NOW (THX to Soren!!!!) for me to create this:

    <any>
    <identity format="struct">100</identity>
    <strenght format="struct">200</strength>
    <test format="string"/>
    </any>

    I need to copy the original attribute (the second:
    type="IDM:RDM/Track:1.0") so i want to become:

    <any>
    <identity format="struct" type="IDM:RDM/Track:1.0>100</identity>
    <strenght format="struct"
    type="IDM:RDM/TrackStrength:1.0">200</strength>
    <test format="string"/>
    </any>

    plz help me :-/
    When you want contact me @ ICQ UIN 67670783
    parvus, Jan 12, 2006
    #13
  14. parvus

    parvus Guest

    It works without problems. But how can I copy the second attrivute?!
    Its no problem NOW (THX to Soren!!!!) for me to create this:

    <any>
    <identity format="struct">100</identity>
    <strenght format="struct">200</strength>
    <test format="string"/>
    </any>

    I need to copy the original attribute (the second:
    type="IDM:RDM/Track:1.0") so i want to become:

    <any>
    <identity format="struct" type="IDM:RDM/Track:1.0>100</identity>
    <strenght format="struct"
    type="IDM:RDM/TrackStrength:1.0">200</strength>
    <test format="string"/>
    </any>

    plz help me :-/
    When you want contact me @ ICQ UIN 67670783
    parvus, Jan 12, 2006
    #14
  15. parvus wrote:

    > "<?xml version="1.0" encoding="UTF-16"?><any><struct
    > type="IDL:RDM/Track:1.0"><id format="ulong">1</id><number
    > format="ulong">100</number></struct></any>"
    >
    > Can i somehow control that my document becomes:
    >
    > <?xml version="1.0" encoding="UTF-16"?>
    > <any>


    Use
    <xsl:eek:utput indent="yes" />
    then in your stylesheet.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 12, 2006
    #15
  16. parvus

    Soren Kuula Guest

    parvus wrote:
    > It works without problems. But how can I copy the second attrivute?!
    > Its no problem NOW (THX to Soren!!!!) for me to create this:


    > I need to copy the original attribute (the second:
    > type="IDM:RDM/Track:1.0") so i want to become:
    >
    > <any>
    > <identity format="struct" type="IDM:RDM/Track:1.0>100</identity>
    > <strenght format="struct"
    > type="IDM:RDM/TrackStrength:1.0">200</strength>
    > <test format="string"/>
    > </any>


    You have an

    <element name=....></element>

    instruction that generated the idendity, strength etc. elements.. right?

    Try adding an attribute constructor:

    <element name=....>
    <attribute name="type"><value-of select="@type"/></attribute>
    </element>

    (this works if the context node is the element that HAS the type
    attribute -- if it IS the type attribute, you have to .. we have talked
    about that already... ;)

    Soren
    Soren Kuula, Jan 12, 2006
    #16
  17. parvus

    parvus Guest

    Yes it works, THX @ Soren again!
    Sorry that you must repeat but im a noob :-(.
    parvus, Jan 13, 2006
    #17
  18. parvus

    parvus Guest

    Hi Soren, sorry for annoying you but i cant realize my problem because
    its to difficult for me :-( and i think its not an easy XML
    transformation. You know what i want and i saw on your hp
    http://dongfang.dk/ that you´re a xml / xslt pro ;-). So i´ll give
    you an excerpt of my XML sourcefile, i need the same structure (!!!!)
    after the transformation. I don´t know how i can realize it, its after
    your help no problem for me to get the value of an attribute and im
    able to create new elements with it, but i don´t know how to create
    nodes and child elements etc. :-(! Here my sourcefile:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <document>
    <struct type="Test:Test/Number:1.0">
    <ulong name="id" type="Test:Test/NumberId:1.0">1</ulong>
    <ulong name="number" type="Test:Test/NumberNumber:1.0">99</ulong>
    <struct name="parvus" type="Test:Test/NumberParvus:1.0">
    <enum name="value" type="Test:Test/NumberValue:1.0"
    values="VALUE_UNKNOWN VALUE_KNOWN">VALUE_UNKNOWN</enum>
    <string name="martin"
    type="Test:Test/NumberMartin:1.0">unknown</string>
    <string name="blacksheep"
    type="Test:Test/NumberBlackSheep:1.0">peanut butter</string>
    </struct>
    <enum name="andi" type="Test:Test/NumberAndi:1.0"
    values="ANDI_UNKNOWN ANDI_FRIEND ANDI_KNOWN">ANDI_UNKNOWN</enum>
    <struct name="schalke" type="Test:Test/NumberSchalke:1.0">
    <ulong name="minplace">0</ulong>
    <ulong name="maxplace">10</ulong>
    <string name="icke" type="Test:Test/NumberIcke:1.0">unknown</string>
    <string name="bella"
    type="Test:Test/NumberBella:1.0">unknown</string>
    </struct>
    </struct>
    </document>

    Can you pleeeeeeeeeeeeeeeaaaaaaaaaaaaaassssssssssse help me? I need the
    same structure! It´s only the thing that the elements should not call
    "struct, string ...." but they should call like the value of the "name"
    attribute. Furthermore i add an attribute with the "datatype" like
    datatype="string". Sadly i can´t realize it on my own :-( you´re my
    last hope. You can contact me: parvus23 (at) web.de Thank you very much
    indeed!
    parvus, Jan 13, 2006
    #18
    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. Stylus Studio
    Replies:
    0
    Views:
    656
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,678
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    621
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    719
    Henry S. Thompson
    Oct 19, 2005
  5. =?UTF-8?b?5byg6Z+h5q2m?=
    Replies:
    3
    Views:
    704
    DeepthiShri
    Oct 23, 2006
Loading...

Share This Page