[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: How to declaratively describe a mapping that invol
Remember that <xsl:analyze-string> takes a variable for the regex if
you use an attribute value template.
Could you compose the regex based on your semantic requirements, then
parse the string using that regex? If you track your left
parentheses, you may be able to hardwire the regex-group() arguments
and just tweak your regex accordingly.
Once you have a matching substring, then you can compose your output
structure accordingly.
Forgive me, but I have no time to draft this for you. I'm writing
this as I rush along my day today.
I hope this helps.
. . . . . . . Ken
At 2024-03-12 13:21 +0000, Roger L Costello costello@xxxxxxxxx wrote:
Hi Folks,
I am mapping an old XML format to a new XML format.
To carry out the mapping, I want to write as little code as
possible; instead, I want to declaratively describe the mapping in
an XML document and then have a tiny piece of generic code which,
with little or no knowledge of the old and new formats, carries out
the mappings described in the XML document.
I am having a hard time with some descriptions. Here's an illustration:
I want to map this old XML:
<Magnetic_Variation>W0150</Magnetic_Variation>
to this new XML:
<magneticVariation>
<magneticVariationEWT>West</magneticVariationEWT>
<magneticVariationValue>015.0</magneticVariationValue>
</magneticVariation>
Here is one way to perform the mapping:
<magneticVariation>
<magneticVariationEWT>
<xsl:value-of select="
if (substring($magVar,1,1) eq 'E') then 'East'
else if (substring($magVar,1,1) eq 'W') then 'West'
else 'True'"/>
</magneticVariationEWT>
<magneticVariationValue>
<xsl:value-of select="
concat(substring($magVar,2,3),'.',substring($magVar,5,1))"/>
</magneticVariationValue>
</magneticVariation>
That is a fine way to perform the mapping. However, it is not the
way that I want to do it because the mapping is expressed
procedurally, not declaratively. I want the mapping expressed declaratively.
I can declaratively express part of the mapping -- map the first
character E to East, W to West, T to True -- using this description:
<Magnetic_Variation>
<mapping>
<old>
<Magnetic_Variation col="1" length="1">E</Magnetic_Variation>
</old>
<new>
<magneticVariationEWT>East</magneticVariationEWT>
</new>
</mapping>
<mapping>
<old>
<Magnetic_Variation col="1" length="1">W</Magnetic_Variation>
</old>
<new>
<magneticVariationEWT>West</magneticVariationEWT>
</new>
</mapping>
<mapping>
<old>
<Magnetic_Variation col="1" length="1">T</Magnetic_Variation>
</old>
<new>
<magneticVariationEWT>True</magneticVariationEWT>
</new>
</mapping>
</Magnetic_Variation>
I do not know how to declaratively describe the other part of the
mapping -- map dddd to ddd.d (where d = digit). I could do this:
<mapping>
<old>
<Magnetic_Variation col="2" length="4"></Magnetic_Variation>
</old>
<new>
<magneticVariationValue>concat(substring($magVar,2,3),'.',substring($magVar,5,1))</magneticVariationValue>
</new>
</mapping>
But that is unacceptable (to me) because the description contains code.
How do I declaratively describe this mapping?
Bonus points if you can also answer this question:
Computer Science Theory Question: If it is impossible to
declaratively express the above mapping, does that mean there is a
limit to declarative descriptions? Is the set of declarative
descriptions smaller than the set of procedural descriptions?
/Roger
--
Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ |
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Streaming hands-on XSLT/XPath 2 training class @US$125 (5 hours free) |
Essays (UBL, XML, etc.) http://www.linkedin.com/today/author/gkholman |
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|