Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Dynamic Transform? >Thread Next - RE: Dynamic Transform? RE: Dynamic Transform?To: NULL Date: 5/1/2007 6:42:00 AM Hi Lucius, As for the XSLT transforming scenario you mentioned, I think you can consider the following two approachs: 1. Use standard xslt/xpath functions to parse the XML document, and check the attribute, if attribute exists, output attribute value, otherwise, output a default value. Here is a test XSLT template demonstrate on this: =========xslt============ <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <table> <tr> <th>Product1</th> <th>TotalProducts</th> <th>LOCA</th> <th>LOCB</th> </tr> <xsl:for-each select="/Data/Table" > <tr> <td> <xsl:value-of select="@ProductName" /> </td> <td> <xsl:value-of select="@TotalProducts" /> </td> <td> <xsl:choose> <xsl:when test="@LOCA"> <xsl:value-of select="@LOCA" /> </xsl:when> <xsl:otherwise> Missing LOCA </xsl:otherwise> </xsl:choose> </td> <td> <xsl:choose> <xsl:when test="@LOCB"> <xsl:value-of select="@LOCB" /> </xsl:when> <xsl:otherwise> Missing LOCB </xsl:otherwise> </xsl:choose> </td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet> ================================ =====test data============= <?xml version="1.0" encoding="utf-8" ?> <Data> <Table TableId="1" ProductName="Product1" TotalProducts="100" LOCA="65" LOCB="35" /> <Table TableId="2" ProductName="Product2" TotalProducts="225" LOCA="125" LOCB="100" /> <Table TableId="3" ProductName="Product3" TotalProducts="225" LOCB="100" /> <Table TableId="4" ProductName="Product4" TotalProducts="225" /> </Data> ================== 2. If you're using .NET framework API to perform the XSLT transformation, you can consider use the script (or .net managed) extension to define some custom function to use in the XSLT template. here are some article and thread discussing on using custom extension functions in .NET XSLT execution: #How to pass Node sets to Inline XSLT Script Functions by Using Visual C# .NET http://support.microsoft.com/kb/330602 #xslt substitute() or xslt 2.0 Options http://groups.google.com/group/microsoft.public.scripting.hosting/browse_thr ead/thread/4b2303bdad22237a/0449287ddf6a3908 Your custom function and test the certain attribute value and return different value according to whether the attribute is null or not. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
