Featured post
xml - how to put templates/inheritance in config files? -
i'm working on model variety of categories of objects, each variety of versions. i'd have these available defaults in config file, allow users customize defaults.
this general case like:
<containers> <container1> <object1> <param1>42</param1> <param2>3.14159</param2> </object1> <object2> <param3>2.71828</param3> <param4>auto</param4> </object2> </container1> </containers>
i process next block , have resulting object structure identical created previous block.
<templates> <object1 id="object1_1.0"> <param1>42</param1> <param2>1</param2> </object1> <object2 id="object2_1.0"> <param3>2</param3> <param4>auto</param4> </object2> </templates> <containers> <container1> <object1 ref="object1_1.0"> <!--param1 "inherited" "42"--> <param2>3.14159</param2> </object1> <object2 ref="object2_1.0"> <param3>2.71828</param3> <!--param4 "inherited" "auto"--> </object2> </container1> </containers>
that is, able same tree reading in these 2 different input files. expect read in xml , process resulting tree before being able generate object tree.
i've been unable find references being done in other projects--i'm not sure how search it. if you've done this, how did approach it? otherwise, how think would? or have tried , found more complicated it's worth?
you can use xslt like:
<?xml version="1.0" encoding="utf-8"?>
<xsl:template match="/"> <xsl:apply-templates select="@*|node()"/> </xsl:template> <!-- process containers --> <xsl:template match="containers"> <xsl:for-each select="child::node()"> <!--copy container node --> <xsl:copy> <xsl:for-each select="child::node()"> <xsl:copy> <!-- first copy template node --> <xsl:for-each select="//node()[@id=current()/attribute::ref]/child::node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:for-each> <!--then object nodes --> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:for-each> </xsl:copy> </xsl:for-each> </xsl:template> <!-- ===================================================== recursive copy, skip templates nodes , ref attributes --> <xsl:template match="@ref"/> <xsl:template match="templates"/> <!-- skip ref attributes --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
it not perfect, because doesn't remove duplicate params, should doable (or use xslt step).
- Get link
- X
- Other Apps
Comments
Post a Comment