How can i transform XML document with XSL Transform policy?

Hi Apigeeks, I have a document based on XML format. I would like to transform in to XHTML document. Does anyone can help me about on this? @Anil Sagar @David Allen

<catalog>
  <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <genre>Computer</genre>
    <price>44.95</price>
    <publish_date>2000-10-01</publish_date>
    <description>An in-depth look at creating applications with XML.</description>
  </book>
  <book id="bk102">
    <author>Ralls, Kim</author>
    <title>Midnight Rain</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2000-12-16</publish_date>
    <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description>
  </book>
  <book id="bk103">
    <author>Corets, Eva</author>
    <title>Maeve Ascendant</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2000-11-17</publish_date>
    <description>After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society.</description>
  </book>
  <book id="bk104">
    <author>Corets, Eva</author>
    <title>Oberon's Legacy</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2001-03-10</publish_date>
    <description>In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant.</description>
  </book>
  <book id="bk105">
    <author>Corets, Eva</author>
    <title>The Sundered Grail</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2001-09-10</publish_date>
    <description>The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy.</description>
  </book>
  <book id="bk106">
    <author>Randall, Cynthia</author>
    <title>Lover Birds</title>
    <genre>Romance</genre>
    <price>4.95</price>
    <publish_date>2000-09-02</publish_date>
    <description>When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled.</description>
  </book>
  <book id="bk107">
    <author>Thurman, Paula</author>
    <title>Splish Splash</title>
    <genre>Romance</genre>
    <price>4.95</price>
    <publish_date>2000-11-02</publish_date>
    <description>A deep sea diver finds true love twenty thousand leagues beneath the sea.</description>
  </book>
  <book id="bk108">
    <author>Knorr, Stefan</author>
    <title>Creepy Crawlies</title>
    <genre>Horror</genre>
    <price>4.95</price>
    <publish_date>2000-12-06</publish_date>
    <description>An anthology of horror stories about roaches, centipedes, scorpions  and other insects.</description>
  </book>
  <book id="bk109">
    <author>Kress, Peter</author>
    <title>Paradox Lost</title>
    <genre>Science Fiction</genre>
    <price>6.95</price>
    <publish_date>2000-11-02</publish_date>
    <description>After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum.</description>
  </book>
  <book id="bk110">
    <author>O'Brien, Tim</author>
    <title>Microsoft .NET: The Programming Bible</title>
    <genre>Computer</genre>
    <price>36.95</price>
    <publish_date>2000-12-09</publish_date>
    <description>Microsoft's .NET initiative is explored in detail in this deep programmer's reference.</description>
  </book>
  <book id="bk111">
    <author>O'Brien, Tim</author>
    <title>MSXML3: A Comprehensive Guide</title>
    <genre>Computer</genre>
    <price>36.95</price>
    <publish_date>2000-12-01</publish_date>
    <description>The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more.</description>
  </book>
  <book id="bk112">
    <author>Galos, Mike</author>
    <title>Visual Studio 7: A Comprehensive Guide</title>
    <genre>Computer</genre>
    <price>49.95</price>
    <publish_date>2001-04-16</publish_date>
    <description>Microsoft Visual Studio 7 is explored in depth, looking at how Visual Basic, Visual C++, C#, and ASP+ are integrated into a comprehensive development environment.</description>
  </book>
</catalog>

Solved Solved
0 4 2,036
1 ACCEPTED SOLUTION

Hi @Hasan

To use the XSL Transform policy, I suggest that you follow these steps:

  • obtain a sample XML file. (You have this , posted it in your question)
  • write and test the XSLT. *More notes on this below.
  • once the XSLT is debugged, configure the XSLT policy as described in the Apigee documentation. **More comments on this below.
  • Embed the XSL policy into an Edge API proxy . If you are transforming a request, place the policy on the request flow. If you are transforming a response, place the policy on a response flow. If you are transforming "something else", then you can place the XSL policy where-ever it is appropriate.

*Notes on write/test/debug of XSLT:

XSLT can be a challenge to develop. To make it simpler, get the proper tools and support. I can suggest:

  • check out Altova XML Spy. It has a number of capabilities that can help with XML or XSL.
  • read up on XSLT. if you need a tutorial, Zvon.org has a nice one.
  • get a command-line XSLT processor, to allow yourself to test xslt easily. I myself use a utility Java program to run XSLT. On MacOSX, there is a tool called 'xsltproc'. http://xmlsoft.org/XSLT/xsltproc2.html . If you download the saxon PE, you can do something like this:
    java -jar saxon-9.1.0.8.jar /full/path/to/xml_data.xml \ 
         /full/path/to/transform.xsl 
    

    I prefer to write my own as I can include debugging. See attached.xslt-tool.zip

**Notes on configuring the Apigee Edge policy:

A sample configuration is below.

<XSL name="TransformXML">
  <ResourceURL>xsl://my_transform.xsl</ResourceURL>
  <Source>request</Source>
</XSL>

The ResourceURL element refers to your XSLT, the stylesheet that you developed, tested, and debugged externally. You should upload this XSLT into the API Proxy Editor, and name it appropriately. Place the name you have chosen for your uploaded XSLT into the text node of the ResourceURL element, prefaced by "xsl://". In the above, the name of the XSLT is "my_transform.xsl" but you can choose and specify any name you wish. End the name with ".xsl".

Specify in the Source element, a variable that contains an XML document, or a variable that contains a request or response, either of which contains XML in the content. For the latter, the message must have content-type:application/xml or content-type:text/xml.

Anything else?

View solution in original post

4 REPLIES 4

@Ivan Novakov

hi i realized that you have an idea of xsl transform policy. can you help me on this? thank you

Hi @Hasan

I'm not clear on what you want to do. It seems to say in your original question that you want to transform an XML document TO an XSLT document. That doesn't make sense to me.

Can you give an example one-record input and one-record output of the kind of transform you want to perform?

If you simply want to apply an XSLT transform, there is support for XSLT transformations in Apigee Edge. It is described here. Beyond what is described there, what other information do you require?

Actually its my question which is "I would like to transform XML document with XSLT schema and output as XHTML file." I dont know how to apply this policy if i gave any of the document type which is XML.

Sorry about my explanation. I just realized that i couldn't explain truely.

Hi @Hasan

To use the XSL Transform policy, I suggest that you follow these steps:

  • obtain a sample XML file. (You have this , posted it in your question)
  • write and test the XSLT. *More notes on this below.
  • once the XSLT is debugged, configure the XSLT policy as described in the Apigee documentation. **More comments on this below.
  • Embed the XSL policy into an Edge API proxy . If you are transforming a request, place the policy on the request flow. If you are transforming a response, place the policy on a response flow. If you are transforming "something else", then you can place the XSL policy where-ever it is appropriate.

*Notes on write/test/debug of XSLT:

XSLT can be a challenge to develop. To make it simpler, get the proper tools and support. I can suggest:

  • check out Altova XML Spy. It has a number of capabilities that can help with XML or XSL.
  • read up on XSLT. if you need a tutorial, Zvon.org has a nice one.
  • get a command-line XSLT processor, to allow yourself to test xslt easily. I myself use a utility Java program to run XSLT. On MacOSX, there is a tool called 'xsltproc'. http://xmlsoft.org/XSLT/xsltproc2.html . If you download the saxon PE, you can do something like this:
    java -jar saxon-9.1.0.8.jar /full/path/to/xml_data.xml \ 
         /full/path/to/transform.xsl 
    

    I prefer to write my own as I can include debugging. See attached.xslt-tool.zip

**Notes on configuring the Apigee Edge policy:

A sample configuration is below.

<XSL name="TransformXML">
  <ResourceURL>xsl://my_transform.xsl</ResourceURL>
  <Source>request</Source>
</XSL>

The ResourceURL element refers to your XSLT, the stylesheet that you developed, tested, and debugged externally. You should upload this XSLT into the API Proxy Editor, and name it appropriately. Place the name you have chosen for your uploaded XSLT into the text node of the ResourceURL element, prefaced by "xsl://". In the above, the name of the XSLT is "my_transform.xsl" but you can choose and specify any name you wish. End the name with ".xsl".

Specify in the Source element, a variable that contains an XML document, or a variable that contains a request or response, either of which contains XML in the content. For the latter, the message must have content-type:application/xml or content-type:text/xml.

Anything else?