RE: [xsl] More newbie questions

Subject: RE: [xsl] More newbie questions
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Tue, 22 Mar 2005 09:18:17 +0200

> Here is a sample of some XML I need to deal with:
> <Root>
> <Database DatabaseName="2004DATA" />
> <Response>
> 	<Record number="1">
> 		<Field FieldName="DOCID">SAP1234</Field>
> 		<Field FieldName="COUNTRY">USA</Field>
> 		<Field FieldName="CITY">Baltimore</Field>
> 		<Field FieldName="TEXT">Baltimore is a
> &lt;b&gt;big&lt;/b&gt; city...</Field>
> 	</Record>
> 	<Record number="2">
> 		<Field FieldName="DOCID">XYZ4433</Field>
> 		<Field FieldName="COUNTRY">Canada</Field>
> 		<Field FieldName="CITY">Toronto, Montreal</Field>
> 		<Field FieldName="TEXT">Toronto and Montreal are in
> Canada</Field>
> 	</Record>
> 	<Record number="3">
> 		<Field FieldName="DOCID">ABC123</Field>
> 		<Field FieldName="COUNTRY">Sweden</Field>
> 		<Field FieldName="CITY">Stockholm</Field>
> 		<Field FieldName="TEXT">Stockholm is a
> &lt;b&gt;big&lt;/b&gt; city also...</Field>
> 	</Record>
> <Response>
> </Root>
> 1- My first issue concerns the Database tag. As you can
> see, I receive an XML response with 1 response and
> multiple Records nested within it. I need to
> extract each "Record" and transform it to be different
> XML (no attribute names for one thing...), and I need
> to add the value in the Database tag (2004DATA) to each
> "Record" before inserting the doc as a CLOB into a
> database. The problem is, my limited xsl skills have
> allowed me to extract the data I need, but I can't
> figure out how to get the database name value into each
> record. I tried assigning the value to a variable with

If the current node is Record, then e.g. "../../Database/@DatabaseName" will
give you the database name.

> xsl:variable, but the transformation fails. Any help
> appreciated...
> 2- How would I create multiple CITY tags in the output

With XSLT you don't create "tags in the output", you create a node tree and
then you can serialize that to XML tags.

> when faced with a response like that in record # 2,
> where the value is Toronto, Montreal?  I don't want a
> comma separated value in the body of the tag.

Write a recursive template that tokenizes the stream using COMMA as a
delimiter. See the FAQ, e.g.

> 3- You may have noticed the escaped angle brackets for
> the HTML tags in the TEXT tag value. How do I have them
> display properly? I played with the output="html" and
> the escape attribute to no avail.

See the FAQ again, <>.


Jarno - Hocico: Bloodshed

Current Thread