for-each IDREF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    for-each IDREF

    Hello,

    I'm back with a problem, where I need help with starting.
    I got an XML file that contains a number of elements with IDREF type attributes:
    Code:
    <?xml version="1.0" ?>
    <root>
    // these elements contain all the info for the groups
    // name is of type ID
      <group name="group1" … />
      <group name="group2" … />
      <group name="group3" … />
      <collection>
    // group is of type IDREF
    // there can be any number of elements
        <item group="group1">…</item>
        <item group="group1">…</item>
        <item group="group2">…</item>
      <collection>
    <root>
    in XSL I want to loop over each group of <item> inside the <collection> (ideally using the idref() function) but I do not know all the values of the IDREF attribute (this number may change over time/file/element). Is there any way to get these values?
    Code:
    // desired result
    <div id="group1">
      <a … >
      <a … >
    </div>
    <div id="group2">
      <a … >
    </div>
    I know that I could loop over all elements (using <xsl:sort>) and check if the attribute value is still the same. Is there a more elegant way? (something like getting the IDREF attribute values first and then call it by idref() (or @group))

    Is it possible to somehow get all the ID values of <group> and iterate over each of them?

    thanks

    PS: once I know all the IDREFS inside <collection> there are no problems I can foresee
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Do you mean this? If not, what more are you looking for; what do you mean by idref? Is this a processor specific function, eg Xalan?

    [code=xml]
    <xsl:template match="group">
    <div id="{@name}">
    <xsl:apply-templates select="//collection/item[@group = current()/@name]"/>
    </div>
    </xsl:template>
    [/code]

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      Originally posted by jkmyoung
      what do you mean by idref? Is this a processor specific function, eg Xalan?
      I mean this:
      Code:
      <!ELEMENT item ...>
      <!ATTLIST item 
          group    IDREF    #IMPLIED
          ... >
      I'll dive into the code tomorrow...

      regards

      PS: XML Schema also know ID/IDREF type attribute definitions

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        currently I'm looking into muenchian grouping. will post back if I can see some light....

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          solved it using Muenchian Grouping (pretty much the thing I needed).
          files (too long to post):
          XML (gives YSOD in FF)
          XSL
          DTD

          Comment

          Working...