A funny sight I saw today:
I think they would be proud!
I had an XSLT style sheet that used a C# method to return a multi line string. I wanted it to include the HTML <BR></BR> tag ad specific places within the string but not as literals. After some searching around I found that instead of trying to get the <BR></BR> tag to not be literal, story I could simply use the <pre></pre> tag within my HTML and it would force it to recognize the “/r/n” returned from the C# method.
I needed to find the total purchase order amount given the quantity and line item price on an X12 850 using XSLT and .NET to transform XML into HTML.
In my case:
PO102 = Quantity
PO104 = Price
Add the following to the stylesheet declaration:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://schemas.microsoft.com/BizTalk/EDI/X12/2006" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var userCSharp" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp>">
In your XSLT use the following code, modifying the referenced node and element within your XML
<xsl:variable name="tmpTotal"> <total_amount> <xsl:for-each select="ns0:PO1Loop1"> <item> <xsl:value-of select="ns0:PO1/PO102 * ns0:PO1/PO104"/> </item> </xsl:for-each> </total_amount> </xsl:variable> <total> <!--<xsl:variable name="myTotal" select="msxsl:node-set($tmpTotal)"/>--> <xsl:variable name="myTotal" select="$tmpTotal"/> <xsl:value-of select="sum(msxsl:node-set($myTotal)/total_amount/item)" /> </total>
I needed to count all of the rows in an entire database.
I looked around and came up with a pretty easy way to do this.
Create this stored procedure and when you run it, it will display it for you.
create proc AllTableCount AS BEGIN /*Create temp table to populate the row counts for all of the tables*/ CREATE TABLE #TableRowCount( TableName sysname, [RowCount] int) /*Now actually get the counts*/ EXEC sp_MSforeachtable 'INSERT #TableRowCount (TableName,[RowCount]) SELECT ''?'',Count(*) from ?' /*Finally: sum up all of the counts and show it*/ Select SUM([RowCount]) as [Total Number Of Rows From Database] from #TableRowCount END