Need help with XSLT - grouping tags
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Need help with XSLT - grouping tags

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Need help with XSLT - grouping tags

    I have a problem I'm looking to solve with XSLT, but I'm a bit stumped at how to implement the syntax.

    I basically have a XML file with a structure narrowed down to this:
    Code:
    <ITEM>
     <NAMEVALUE>
      <NAME>From1</NAME>
      <VALUE>From1 Value</VALUE>
     </NAMEVALUE>
     <NAMEVALUE>
      <NAME>From2</NAME>
      <VALUE>From2 Value</VALUE>
     </NAMEVALUE>
     <NAMEVALUE>
      <NAME>Price1</NAME>
      <VALUE>Price1 Value</VALUE>
     </NAMEVALUE>
     <NAMEVALUE>
      <NAME>Price2</NAME>
      <VALUE>Price2 Value</VALUE>
     </NAMEVALUE>
     .
     .
     .
     .
    </ITEM>
    (I can't change the format of the delivered file).

    I would like to transform it into something equivalent to:
    Code:
    <Prices>
     <Price from="From1 Value">Price1 Value</Price>
     <Price from="From2 Value">Price2 Value</Price>
    </Prices>
    I am running scripts in my XSLT file, and can most likely fix it using scripts but I was wondering if it would be possible to either use more pure XSL syntaxt to solve this problem.

    Any advice?

  2. #2
    Join Date
    Oct 2004
    Posts
    107

    Re: Need help with XSLT - grouping tags

    How are you determining which tags link up to each other? Is it like a 2 column thing, where all of 1 value appears first, then all of the 2nd value?

  3. #3
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Need help with XSLT - grouping tags

    They match up based on the "number" in the Name tag value. From1 matches to Price1 and (of course) I can't be guaranteed that they'll always come in the proper pair order, so I can't just match one and count on the next to come in the next namevalue pair.

    So Price2 can come before From1 which comes before From2 and so on.... it is a messed up format, but it is what I have to work with and unfortunately - I have difficulty in finding XSLT syntax to solve it, so I likely have to go another route for my transformation (perhaps a manual transformation or script it).

  4. #4
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Need help with XSLT - grouping tags

    Giving up on the XSLT of this and trying a manual code based transform through streams instead. Looks to perform just as well, but requires more coding from me.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center