xml - How to map an array to fixed fields using Biztalk mapper -
xml - How to map an array to fixed fields using Biztalk mapper -
i need remap array of objects this:
<root> <listofobjs> <obj> <attr1>0000</attr1> <attr2>hello!</attr2> </obj> <obj> <attr1>1111</attr1> <attr2>hello1!</attr2> </obj> </listofobjs> </root>
to output this:
<root> <obj1_attr1>0000</obj1_attr1> <obj1_attr2>hello!</obj1_attr2> <obj2_attr1>1111</obj2_attr1> <obj2_attr2>hello1!</obj2_attr2> </root>
so in xsd schema have this:
schema input <xs:element name="root"> <xs:complextype> <xs:sequence> <xs:element name="listofobjs"> <xs:complextype> <xs:sequence> <xs:element name="obj"> <xs:complextype> <xs:sequence> <xs:element name="attr1"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:minlength value="1"/> <xs:maxlength value="50"/> </xs:restriction> </xs:simpletype> </xs:element> <xs:element name="attr2"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:minlength value="1"/> <xs:maxlength value="50"/> </xs:restriction> </xs:simpletype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype> </xs:element>
schema output <xs:element name="root"> <xs:complextype> <xs:sequence> <xs:element name="obj1_attr1"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:minlength value="1"/> <xs:maxlength value="50"/> </xs:restriction> </xs:simpletype> </xs:element> <xs:element name="obj1_attr2"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:minlength value="1"/> <xs:maxlength value="50"/> </xs:restriction> </xs:simpletype> </xs:element> <xs:element name="obj2_attr1"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:minlength value="1"/> <xs:maxlength value="50"/> </xs:restriction> </xs:simpletype> </xs:element> <xs:element name="obj2_attr2"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:minlength value="1"/> <xs:maxlength value="50"/> </xs:restriction> </xs:simpletype> </xs:element> </xs:sequence> </xs:complextype> </xs:element>
in add-on have evaluate every single value because found conditions, if value=0000 , output should null.
what best way this?
i'm thinking of developing custom functoid i'm not sure best way, done using xslt inline transforms, can point me in best direction?
first of all, there errors on schemas:
the right xsd schema1 has be:
<xs:schema xmlns:b="http://schemas.microsoft.com/biztalk/2003" xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:element name="root"> <xs:complextype> <xs:sequence> <xs:element name="listofobjs"> <xs:complextype> <xs:sequence> <xs:element name="obj" maxoccurs="unbounded"> <xs:complextype> <xs:sequence> <xs:element name="attr1"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:minlength value="1"/> <xs:maxlength value="50"/> </xs:restriction> </xs:simpletype> </xs:element> <xs:element name="attr2"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:minlength value="1"/> <xs:maxlength value="50"/> </xs:restriction> </xs:simpletype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:schema>
i've come following
<?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"> <xsl:template match="/"> <root> <xsl:for-each select="/root/listofobjs/obj"> <xsl:variable name="objname" select="name(.)"/> <xsl:variable name="objpos" select="position()"/> <xsl:for-each select="*"> <xsl:variable name="nodename" select="name(.)"/> <xsl:variable name="name" select="concat($objname, $objpos, $nodename)"/> <xsl:element name="{$name}"> <xsl:value-of select="."/> </xsl:element> </xsl:for-each> </xsl:for-each> </root> </xsl:template> </xsl:stylesheet>
with next input:
<root> <listofobjs> <obj> <attr1>0000</attr1> <attr2>hello!</attr2> </obj> <obj> <attr1>1111</attr1> <attr2>hello1!</attr2> </obj> </listofobjs> </root>
this gives next output:
<?xml version="1.0" encoding="utf-8"?> <root xmlns:msxsl="urn:schemas-microsoft-com:xslt"> <obj1attr1>0000</obj1attr1> <obj1attr2>hello!</obj1attr2> <obj2attr1>1111</obj2attr1> <obj2attr2>hello1!</obj2attr2> </root>
xml xslt xsd biztalk biztalk-mapper
Comments
Post a Comment