Hi Sanjeev,

> On 12 Feb 2019, at 16:31, Sanjeev Devireddy <[email protected]> 
> wrote:
> 
> Hi Richard,
>     Thanks for your response. In our example, first a list of XML tags (tag 
> names are dynamic and with multiple attributes) are prepared by looping 
> through a SPARQL result set and at the end, all these tags are added (as 
> sub-tags) to a root tag, whose name is dynamic.

I understand.

> My understanding is that the only way to create an XML tag with dynamic name 
> is using ui:group & ui:parse as shown below.

That’s the only way I can think of.

> In this case, if all the sub tags are has to be passed as string to the 
> ui:parse while preparing the root tag then the sub tags can't be converted to 
> strings using the ui:format="ui:TEXT”.

I don’t know why you say that.

In your example, you used ui:bind and ui:stringify to do what looked like 
concatenating multiple attributes. I showed how to make that work by adding a 
ui:format.

For sub-tags, you don’t need to use ui:stringify at all, although you can if 
you want to. What you need to do is create the XML string for the sub-tags, and 
insert them when creating the element for the dynamic parent element:

    <ui:parse ui:xml="true" ui:str="&lt;{= ?tagName }&gt; {= ?subTagsXML } 
&lt;/{= ?tagName }&gt;"/>

Below is an example that creates one (static) root element with five dynamic 
top-level elements and five dynamic children. All have a dynamic attribute too. 
It’s in the attached file, call with 
http://localhost:8083/tbl/swp?_viewClass=x:TestService

The key point is that the dynamic elements, including all their attributes and 
children/descendants (and their attributes), need to be produced by string 
concatenation.

Richard



<ui:group>
    <x:RootElement>
        <ui:forEach ui:resultSet="{#
                SELECT ?i
                WHERE {
                    ?i tops:for ( 1 5 ) .
                } }">
            <ui:group let:attr="attribute{= ?i }=&quot;Value {= ?i }&quot;"
                      let:subTag="SubElement{= ?i }"
                      let:topTag="TopLevelElement{= ?i }">
                <ui:group let:subElement="&lt;{= ?subTag } {= ?attr }&gt;Value 
{= ?i }&lt;/{= ?subTag }&gt;">
                    <ui:parse ui:str="&lt;{= ?topTag } {= ?attr }&gt;{= 
?subElement }&lt;/{= ?topTag }&gt;"
                              ui:xml="true"/>
                </ui:group>
            </ui:group>
        </ui:forEach>
    </x:RootElement>
</ui:group>

-- 
You received this message because you are subscribed to the Google Groups 
"TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Attachment: xml-output-test.ui.ttlx
Description: Binary data

Reply via email to