Hi this is my first paste...
[Contains my input.xml and transform.xslt and output file it generated.
.. this contains my new input.xml file..
And in here, all the Activitiy's tag attributes are being rewritten as children.
And here is the xslt which i tried to write and failed...
..

Primarily the main difference, was that in 12700 i was using Activity@routeattri as the key and used it to do the separtion..
But I wanna change it to Activity/routetag as the key now and do the same..

I think the change shld be little but I jez cant seem to figure it out..

Thanks for any help rendered.

Dani AI

Generated

Short summary: changed the grouping key from an attribute to a child element (from an Activity/@routeattr to Activity/routetag). The usual XSLT consequences are (a) the xsl:key/use must be changed to read the child element, and (b) you must be careful whether you are emitting the element node(s) or only their string value (xsl:value-of will give you plain text like "4ID").

Practical steps that fix this reliably:

  • Redefine the key so it uses the child element text (and trim whitespace). For XSLT 1.0, a common pattern is:
<xsl:key name="byRoute" match="Activity" use="normalize-space(routetag)"/>
  • Use the key for grouping with the generate-id trick so you iterate one representative per distinct routetag:
Activity[generate-id() = generate-id(key('byRoute', normalize-space(routetag))[1])]
  • When you want the grouped Activities' child elements (not just the routetag text), select them via the key and then copy or apply-templates. Do not use xsl:value-of on the Activity node if you want element structure preserved; use xsl:apply-templates or xsl:copy-of on the matched nodes.

Troubleshooting and gotchas:

  • Whitespace: child element text often contains extra spaces or newlines; normalize-space() prevents subtle mismatches.
  • Namespaces: if routetag or Activity are in a namespace you must reference them with the same prefix in the XSLT.
  • XSLT version: if you can run XSLT 2.0, xsl:for-each-group with group-by="routetag" is simpler and less error-prone.
  • Debugging tips: temporarily output counts or string-values (count(key(...)), string(key(...)[1])) to confirm keys, and switch from value-of to copy-of/apply-templates to check whether you are losing element markup.

These points address why you saw the raw "4ID" text and how to change the stylesheet so grouped output contains the full element structure you expect.

Recommended Answers

All 4 Replies

qwerty beelzebub buzzword gobbling froobs.

Hi, let me rephrase the question to make it more comprehendable.

Initially, I had input file with this format.
<Activity routeattr="4ID">
but later I had changed it to
<Activity>
<routetag>4ID</routetag>..
The XSLT has to slightly tinkered to allow this modification.

This paste contains Orginal input.xml, transform.xsl and output.xml file

The modiifcation as I mentioned above is that Activity's attribute is swapped to become the Activity's Child.
In this below paste, I have given the new input.xml, transform.xsl( I have highlighted the changes with "CHANGE HERE" comments) and the output.xml file which

As you can see, the output inside the <route> in the output.xml is different in the 2 output.xml files.
Instead of
<route>
<t>Email</t>....
</route>
I gotten this instead
<route>
4ID....
</route>

I hope I have tried my best to clarify my problem as much as I can.
Thanks for any help.

Regards

Just Changing to Solution Icon...
Solution is in the above thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.