Here is an XML file, representing a list of items and their priority levels on a scale of 1-3. When the file was created, the priority levels were not set:
<root>
<section number="1">
<group number="1.1">
<item date="today" priority="Undefined"><title>Item1</title></item>
<item date="today" priority="Undefined"><title>Item2</title></item>
<item date="yesterday" priority="Undefined"><title>Item3</title></item>
</group>
<group number="1.2">
<item date="tomorrow" priority="Undefined"><title>Item4</title></item>
<item date="today" priority="Undefined"><title>Item5</title></item>
<item date="yesterday" priority="Undefined"><title>Item5</title></item>
</group>
</section>
</root>
I was given the list of priorities by item later. They came to me just in a regular text file, but I can put them into any format necessary, including XML. Just to show as an example:
<priorities>
<item1 p="1">
<item2 p="3">
<item3 p="1">
<item4 p="2">
<item5 p="3">
<item6 p="3">
</priorities>
I'm trying to write an XSL transform that sets the priority attributes for each item appropriately.
In my mind, it should work like this (I already have step 1):
- Use the identity transform
- Create some kind of data structure ('Item1':'1', 'Item2':'3', ...)
- Create a template that:
- Matches the ITEM element
- Checks the TITLE
- Looks up that title in the data structure
- Sets the priority level appropriately (I think I know how to do this part)
Alternatively, I thought of another way:
- Use the identity transform (already written)
- Create 3 data structures:
- $P1 := ('Item1', 'Item2')
- $P2 := ('Item4')
- $P3 := ('Item2', 'Item5', 'Item6')
- Create 3 templates, one for each priority level. For example, the P1 template:
- Matches the ITEM element
- Checks the TITLE
- Checks whether the TITLE is a member of $P1:
- If so, set the priority level appropriately
- If not, do nothing
NOTE: This is a distilled example; I am trying to create a solution that can handle an XML file with approximately 600 item elements with very long strings as the TITLEs.
I've been Googling and searching SO and have been left wondering if such a thing is even possible.
Using Oxygen 16.