Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: Dynamic Transform?

From: stcheng@------.---------.--- (------ -----[----])
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.













transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent