I am able to parse xml to json by
http://www.armbruster-it.org/index.php/12-it/pl-sql/12-oracle-xml-and-json-goodies
But when any CDATA come it fail . Can you tell me the rule of xslt so that i can copy all data that is written in CDATA as it is in json .
> select
> packagename.itstar_xml_util.xml2json(xmltype('<ArticleDetail><![CDATA[<P
> class=MsoNormal style="MARGIN: 0in 0in 0pt"></P>]]></ArticleDetail>'))
> FROM DUAL;
This is data
<ArticleDetail><![CDATA[<P class=MsoNormal style="MARGIN: 0in 0in 0pt"></P>]]></ArticleDetail>
The xslt is
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" omit-xml-declaration="yes" method="text" encoding="UTF-8" media-type="text/x-json"/>
<xsl:strip-space elements="*"/>
<!--contant-->
<xsl:variable name="d">0123456789</xsl:variable>
<!-- ignore document text -->
<xsl:template match="text()[preceding-sibling::node() or following-sibling::node()]"/>
<!-- string -->
<xsl:template match="text()">
<xsl:call-template name="escape-string">
<xsl:with-param name="s" select="."/>
</xsl:call-template>
</xsl:template>
<!-- Main template for escaping strings; used by above template and for object-properties
Responsibilities: placed quotes around string, and chain up to next filter, escape-bs-string -->
<xsl:template name="escape-string">
<xsl:param name="s"/>
<xsl:text>"</xsl:text>
<xsl:call-template name="escape-bs-string">
<xsl:with-param name="s" select="$s"/>
</xsl:call-template>
<xsl:text>"</xsl:text>
</xsl:template>
<!-- Escape the backslash (\) before everything else. -->
<xsl:template name="escape-bs-string">
<xsl:param name="s"/>
<xsl:choose>
<xsl:when test="contains($s,''\'')">
<xsl:call-template name="escape-quot-string">
<xsl:with-param name="s" select="concat(substring-before($s,''\''),''\\'')"/>
</xsl:call-template>
<xsl:call-template name="escape-bs-string">
<xsl:with-param name="s" select="substring-after($s,''\'')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="escape-quot-string">
<xsl:with-param name="s" select="$s"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Escape the double quote ("). -->
<xsl:template name="escape-quot-string">
<xsl:param name="s"/>
<xsl:choose>
<xsl:when test="contains($s,'';'')">
<xsl:call-template name="encode-string">
<xsl:with-param name="s" select="concat(substring-before($s,'';''),''"'')"/>
</xsl:call-template>
<xsl:call-template name="escape-quot-string">
<xsl:with-param name="s" select="substring-after($s,'';'')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="encode-string">
<xsl:with-param name="s" select="$s"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Replace tab, line feed and/or carriage return by its matching escape code. Can''t escape backslash
or double quote here, because they don''t replace characters (; becomes \t), but they prefix
characters (\ becomes \\). Besides, backslash should be seperate anyway, because it should be
processed first. This function can''t do that. -->
<xsl:template name="encode-string">
<xsl:param name="s"/>
<xsl:choose>
<!-- tab -->
<xsl:when test="contains($s,'';'')">
<xsl:call-template name="encode-string">
<xsl:with-param name="s" select="concat(substring-before($s,'';''),''\t'',substring-after($s,'';''))"/>
</xsl:call-template>
</xsl:when>
<!-- line feed -->
<xsl:when test="contains($s,'';'')">
<xsl:call-template name="encode-string">
<xsl:with-param name="s" select="concat(substring-before($s,'';''),''\n'',substring-after($s,'';''))"/>
</xsl:call-template>
</xsl:when>
<!-- carriage return -->
<xsl:when test="contains($s,'';'')">
<xsl:call-template name="encode-string">
<xsl:with-param name="s" select="concat(substring-before($s,'';''),''\r'',substring-after($s,'';''))"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$s"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- number (no support for javascript mantise) -->
<xsl:template match="text()[not(string(number())=''NaN'')]">
<xsl:value-of select="."/>
</xsl:template>
<!-- boolean, case-insensitive -->
<xsl:template match="text()[translate(.,''TRUE'',''true'')=''true'']">true</xsl:template>
<xsl:template match="text()[translate(.,''FALSE'',''false'')=''false'']">false</xsl:template>
<!-- item:null -->
<xsl:template match="*[count(child::node())=0]">
<xsl:call-template name="escape-string">
<xsl:with-param name="s" select="local-name()"/>
</xsl:call-template>
<xsl:text>:null</xsl:text>
<xsl:if test="following-sibling::*">,</xsl:if>
<xsl:if test="not(following-sibling::*)">}</xsl:if> <!-- MBR 30.01.2010: added this line as it appeared to be missing from stylesheet -->
</xsl:template>
<!-- object -->
<xsl:template match="*" name="base">
<xsl:if test="not(preceding-sibling::*)">{</xsl:if>
<xsl:call-template name="escape-string">
<xsl:with-param name="s" select="name()"/>
</xsl:call-template>
<xsl:text>:</xsl:text>
<xsl:apply-templates select="child::node()"/>
<xsl:if test="following-sibling::*">,</xsl:if>
<xsl:if test="not(following-sibling::*)">}</xsl:if>
</xsl:template>
<!-- array -->
<xsl:template match="*[count(../*[name(../*)=name(.)])=count(../*) and count(../*)>1]">
<xsl:if test="not(preceding-sibling::*)">[</xsl:if>
<xsl:choose>
<xsl:when test="not(child::node())">
<xsl:text>null</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="child::node()"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="following-sibling::*">,</xsl:if>
<xsl:if test="not(following-sibling::*)">]</xsl:if>
</xsl:template>
<!-- convert root element to an anonymous container -->
<xsl:template match="/">
<xsl:apply-templates select="node()"/>
</xsl:template>
</xsl:stylesheet>
Related
I am using XSLT v1.0 and running it through Microsoft Visual Studio.
I have data (which will be different in every node) but is structured like this:
<ItemGroupData ItemGroupOID="DDG4">
<ItemDataString ItemOID="DDLOCC" AuditRecordID="AR.8452551">5,8,9,2,3</ItemDataString>
<ItemDataString ItemOID="DDLOCL" AuditRecordID="AR.8452551">1,7</ItemDataString>
<ItemDataString ItemOID="DDLOCR" AuditRecordID="AR.8452551">1</ItemDataString>
</ItemGroupData>
There can be any number of values separated by commas in each of the 3 fields.
I am trying to split the data so I can work with each individual integer, and have tried the method suggested by Dimitre Novatchev here: split function in xslt 1.0, but it keeps giving me the error:
"'template' is not a recognized extension element. An error occurred at (0,0).".
The new split/mark templates I created are inside my overall template, which is being used to convert my XML to a CSV file.
Can I have a template within a template? Or do I need to define it outside the main template? Bit of a N00b with XML so any help would be greatly appreciated.
My new templates (note the processedItem bit has been simplified for demonstration purposes):
<xsl:template match="mark">
<xsl:variable name="vrtfSplit">
<xsl:apply-templates/>
</xsl:variable>
<xsl:for-each select="ext:node-set($vrtfSplit)/*">
<processedItem>
<xsl:if test="$varLOCOID='DDLOCL'">
<xsl:value-of select="current() * 100"/>
</xsl:if>
<xsl:if test="$varLOCOID='DDLOCC'">
<xsl:value-of select="current() * 10"/>
</xsl:if>
<xsl:if test="$varLOCOID='DDLOCR'">
<xsl:value-of select="current() * 150"/>
</xsl:if>
</processedItem>
</xsl:for-each>
</xsl:template>
<xsl:template match="text()" name="split">
<xsl:param name="pText" select="."/>
<xsl:if test="string-length($pText) > 0">
<item>
<xsl:value-of select="substring-before(concat($pText, ','), ',')"/>
</item>
<xsl:call-template name="split">
<xsl:with-param name="pText" select="substring-after($pText, ',')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
Consider the following example:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/ItemGroupData">
<output>
<xsl:apply-templates/>
</output>
</xsl:template>
<xsl:template match="ItemDataString">
<items>
<xsl:call-template name="tokenize-and-process">
<xsl:with-param name="text" select="."/>
<xsl:with-param name="factor">
<xsl:choose>
<xsl:when test="#ItemOID='DDLOCL'">100</xsl:when>
<xsl:when test="#ItemOID='DDLOCC'">10</xsl:when>
<xsl:when test="#ItemOID='DDLOCR'">150</xsl:when>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</items>
</xsl:template>
<xsl:template name="tokenize-and-process">
<xsl:param name="text"/>
<xsl:param name="factor" select="1"/>
<xsl:param name="delimiter" select="','"/>
<xsl:variable name="token" select="substring-before(concat($text, $delimiter), $delimiter)" />
<item>
<xsl:value-of select="$token * $factor"/>
</item>
<xsl:if test="contains($text, $delimiter)">
<!-- recursive call -->
<xsl:call-template name="tokenize-and-process">
<xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
<xsl:with-param name="factor" select="$factor"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Applied to your example input XML, the result will be:
Result
<?xml version="1.0" encoding="UTF-8"?>
<output>
<items>
<item>50</item>
<item>80</item>
<item>90</item>
<item>20</item>
<item>30</item>
</items>
<items>
<item>100</item>
<item>700</item>
</items>
<items>
<item>150</item>
</items>
</output>
P.S. No, a template cannot be a child of another template.
after getting hints here: xslt string replace concrete example,
I've made these two templates to use in my own environment.
They use html-tables in order to get some formatting done when calling the second template (fhb-bib-info) from yet another .xsl-template:
<xsl:template name="string-replace-all">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="$text = '' or $replace = ''or not($replace)" >
<!-- Prevent this routine from hanging -->
<xsl:value-of select="$text" />
</xsl:when>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)" />
<xsl:value-of select="$by" />
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fhb-bib-info">
<xsl:choose>
<xsl:when test="./bib-info =''">
<tr>
<td colspan="2"><xsl:text>Autor: </xsl:text><xsl:value-of select="./z13-author"/></td>
</tr>
<tr>
<td colspan="2"><xsl:text>Titel: </xsl:text><xsl:value-of select="./z13-title"/></td>
</tr>
<tr>
<td colspan="2"><xsl:text>ISBN/ISSN: </xsl:text><xsl:value-of select="./z13-isbn-issn"/></td>
</tr>
</xsl:when>
<xsl:otherwise>
<xsl:template match="bib-info">
<xsl:variable name="newtext">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="text()" />
<xsl:with-param name="replace" select="']: '" />
<xsl:with-param name="by" select="']: '" />
</xsl:call-template>
</xsl:variable>
</xsl:template>
<tr>
<td colspan="2"><bib-info><xsl:value-of select="$newtext" /></bib-info></td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
But when I try to run them I get the following errors. The two templates are part of the file funcs.xsl. Line 153 is where the xsl:value-of select="$newtext" statement occurs.
Can anybody help me debug/clear these error-messages? Kate
Error at xsl:value-of on line 153 of file:/C:/Aleph-22-Test/alephcom/files/SWF50/PrintTemplates/ger/funcs.xsl:
XPST0008: XPath syntax error at char 8 on line 153 in {$newtext}:
Variable $newtext has not been declared
Error at xsl:template on line 143 of file:/C:/Aleph-22-Test/alephcom/files/SWF50/PrintTemplates/ger/funcs.xsl:
XTSE0010: An xsl:otherwise element must not contain an xsl:template element
Error at xsl:template on line 143 of file:/C:/Aleph-22-Test/alephcom/files/SWF50/PrintTemplates/ger/funcs.xsl:
XTSE0010: Element must be used only at top level of stylesheet
With the help of a colleague I managed to solve my problem and debug my code so that my templates now work as wanted. The crucial flaw in my logic was that I expected to have to specifically display the bib-info-element after the replace-action. I found out that's not the case.
Another thing is the need for a recursiv call on the replace-action as only on blanc is being replaced instead of the whole bunch.
So here's the working code:
<xsl:template name="plain-fhb-bib-info">
<xsl:choose>
<xsl:when test="./bib-info =''">
<xsl:text>Autor: </xsl:text><xsl:value-of select="./z13-author"/><xsl:call-template name="new-line"/>
<xsl:text>Titel: </xsl:text><xsl:value-of select="./z13-title"/><xsl:call-template name="new-line"/>
<xsl:text>ISBN/ISSN: </xsl:text><xsl:value-of select="./z13-isbn-issn"/><xsl:call-template name="new-line"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="plain-string-replace-all-recursive">
<xsl:with-param name="text" select="./bib-info" />
<xsl:with-param name="replace" select="']: '" />
<xsl:with-param name="by" select="']: '" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- recursively applies plain-string-replace-all until there are no more matches -->
<xsl:template name="plain-string-replace-all-recursive">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:variable name="newtext">
<xsl:call-template name="plain-string-replace-all">
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="plain-string-replace-all-recursive">
<xsl:with-param name="text" select="$newtext" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="plain-string-replace-all">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="$text = '' or $replace = ''or not($replace)" >
<xsl:value-of select="$text" />
</xsl:when>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)" />
<xsl:value-of select="$by" />
<xsl:call-template name="plain-string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
In Microsoft Dynamics GP I need to set the tax on individual orders as taxable/non-taxable (cannot be done on customer record).
For some reason no matter what I pass into the CreateSalesOrder call for the web services, it will not save the tax information.
I've tried:
Using the CreateSalesInvoice policy which has had "Create Taxes Behavior" set to "Taxes will be provided"
Overrode policies using "Use Header Level Taxes Behavior" and "Create Taxes Behavior" all 4 modes have been tried.
Provided taxes as a total on the Sales Order
Provided taxes as a tax detail on the sales order
Provided taxes as a total on the line item
Provided taxes as a tax detail on the sales order
Set the TaxScheduleKey on the order
Set the TaxScheduleKey on the line items
Taxes just get blanked out in GP, it's infuriating... Any ideas? I do have access to the Dynamics database but I'd really rather not go that route if possible.
My research has led me to believe that this is broken (every thread on this subject ends with no answers) and Microsoft isn't going to fix it, but that really hurts automation something awful.
Ran into this issue today. A little background:
After trying everything outlined above, modifying policies - particularly, Sales Document - Create Sales Document policies, and becoming frustrated at there being no policies for Create Sales Order to allow taxes to be specified, I came across this MSDN article about how the GP Services could be designed or extended: https://msdn.microsoft.com/en-us/library/dd996499.aspx
Not interested in going quite that far, I found - "Program Files\Microsoft Dynamics\GPWebServices\XSLT", in particular, the "Microsoft.Dynamics.GP.SalesOrderCreate.xslt" file.
As it comes installed with GreatPlains, there are no transforms in place to utilize incoming tax data at all (no surprise, given what had been tried). USINGHEADERLEVELTAXES is set to 0.
Combining the Tax lines from the "Microsoft.Dynamics.GP.SalesInvoiceCreate.xslt" file into the SalesOrderCreate.xslt file, you can modify the XML sent into eConnect for SalesOrderCreate to properly create the Taxes.
The below example uses/was tested for header level tax behavior.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mbs="http://schemas.microsoft.com/dynamics/2006/01"
xmlns:gputil="urn:Microsoft.Dynamics.GP.TransformUtilities"
version="1.0">
<xsl:import href="Microsoft.Dynamics.GP.SalesCreateUpdateLibrary.xslt"/>
<xsl:import href="Microsoft.Dynamics.GP.StandardLibrary.xslt"/>
<xsl:variable name="CompanyId">
<xsl:value-of select="/SalesOrder/mbs:Context/mbs:OrganizationKey/mbs:Id"/>
</xsl:variable>
<xsl:template match ="/">
<eConnect xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:apply-templates />
</eConnect>
</xsl:template>
<xsl:template match="SalesOrder">
<SOPTransactionType>
<xsl:apply-templates select="Lines/SalesOrderLine/Serials/SalesLineSerial">
<xsl:with-param name="UpdateIfExists">0</xsl:with-param>
</xsl:apply-templates>
<xsl:apply-templates select="Lines/SalesOrderLine/Components/SalesOrderComponent/Serials/SalesComponentSerial">
<xsl:with-param name="UpdateIfExists">0</xsl:with-param>
</xsl:apply-templates>
<xsl:apply-templates select="Lines/SalesOrderLine/Lots/SalesLineLot">
<xsl:with-param name="UpdateIfExists">0</xsl:with-param>
</xsl:apply-templates>
<xsl:apply-templates select="Lines/SalesOrderLine/Components/SalesOrderComponent/Lots/SalesComponentLot">
<xsl:with-param name="UpdateIfExists">0</xsl:with-param>
</xsl:apply-templates>
<xsl:apply-templates select="Lines/SalesOrderLine" />
<xsl:apply-templates select="Lines/SalesOrderLine/Components/SalesOrderComponent" />
<xsl:apply-templates select="TrackingNumbers/SalesTrackingNumber" />
<xsl:apply-templates select="Taxes/SalesDocumentTax" />
<xsl:apply-templates select="Commissions/SalesCommission" />
<xsl:apply-templates select="Payments/SalesPayment">
<xsl:with-param name="UpdateIfExists">0</xsl:with-param>
</xsl:apply-templates>
<xsl:apply-templates select="UserDefined" />
<xsl:apply-templates select="Lines/SalesOrderLine/Bins/SalesLineBin" />
<xsl:apply-templates select="Lines/SalesOrderLine/Components/SalesOrderComponent/Bins/SalesComponentBin" />
<xsl:call-template name="SalesHeader" />
<xsl:apply-templates select="ProcessHolds/SalesProcessHold">
<xsl:with-param name="UpdateIfExists">0</xsl:with-param>
</xsl:apply-templates>
</SOPTransactionType>
</xsl:template>
<xsl:template match="SalesOrderLine">
<taSopLineIvcInsert>
<xsl:call-template name="CreateUpdateLine">
<xsl:with-param name="UpdateIfExists">0</xsl:with-param>
<xsl:with-param name="CompanyId">
<xsl:value-of select="$CompanyId" />
</xsl:with-param>
</xsl:call-template>
<xsl:if test="QuantityToBackorder/Value != ''">
<QTYTBAOR>
<xsl:value-of select="QuantityToBackorder/Value" />
</QTYTBAOR>
</xsl:if>
<xsl:if test="QuantityToInvoice/Value != ''">
<QUANTITY>
<xsl:value-of select="QuantityToInvoice/Value" />
</QUANTITY>
</xsl:if>
<xsl:if test="QuantityCanceled/Value != ''">
<QTYCANCE>
<xsl:value-of select="QuantityCanceled/Value" />
</QTYCANCE>
</xsl:if>
<xsl:if test="QuantityFulfilled/Value != ''">
<QTYFULFI>
<xsl:value-of select="QuantityFulfilled/Value" />
</QTYFULFI>
</xsl:if>
<xsl:if test="TaxAmount/Value != ''">
<TAXAMNT>
<xsl:value-of select="TaxAmount/Value" />
</TAXAMNT>
</xsl:if>
<RecreateDist>0</RecreateDist>
</taSopLineIvcInsert>
</xsl:template>
<xsl:template match="SalesOrderComponent">
<taSopLineIvcInsertComponent>
<xsl:call-template name="CreateUpdateComponent">
<xsl:with-param name="UpdateIfExists">0</xsl:with-param>
</xsl:call-template>
<xsl:if test="QuantityToBackorder/Value != ''">
<QTYTBAOR>
<xsl:value-of select="QuantityToBackorder/Value" />
</QTYTBAOR>
</xsl:if>
<xsl:if test="QuantityToInvoice/Value != ''">
<QUANTITY>
<xsl:value-of select="QuantityToInvoice/Value" />
</QUANTITY>
</xsl:if>
<xsl:if test="QuantityCanceled/Value != ''">
<QTYCANCE>
<xsl:value-of select="QuantityCanceled/Value" />
</QTYCANCE>
</xsl:if>
<xsl:if test="QuantityFulfilled/Value != ''">
<QTYFULFI>
<xsl:value-of select="QuantityFulfilled/Value" />
</QTYFULFI>
</xsl:if>
</taSopLineIvcInsertComponent>
</xsl:template>
<xsl:template name="SalesHeader">
<taSopHdrIvcInsert>
<xsl:call-template name="CreateUpdateDocument">
<xsl:with-param name="UpdateIfExists">0</xsl:with-param>
<xsl:with-param name="CompanyId">
<xsl:value-of select="$CompanyId" />
</xsl:with-param>
</xsl:call-template>
<xsl:if test="PaymentAmount/Value != ''">
<PYMTRCVD>
<xsl:value-of select="PaymentAmount/Value" />
</PYMTRCVD>
</xsl:if>
<xsl:if test="TaxAmount/Value != ''">
<TAXAMNT>
<xsl:value-of select="TaxAmount/Value" />
</TAXAMNT>
</xsl:if>
<USINGHEADERLEVELTAXES>1</USINGHEADERLEVELTAXES>
<CREATEDIST>0</CREATEDIST>
<CREATETAXES>0</CREATETAXES>
</taSopHdrIvcInsert>
</xsl:template>
</xsl:stylesheet>
I'm trying to make a custom filter which sorts on authors (users) in the SharePoint 2013 blog. I'm working with XSL dataview and it's exported to a web part. I have a column called Author which gets the information from Created By. When I click on a user in the web part it shows all posts instead of the selected author. The URL is mysite/default.aspx?Author=FirstName LastName".
Code (default.aspx):
<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
<xsl:call-template name="dvt_1"/>
</xsl:template>
<xsl:template name="dvt_1">
<xsl:variable name="dvt_StyleName">RepForm3</xsl:variable>
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[not(#Author.title=preceding-sibling::Row/#Author.title)]" />
<xsl:call-template name="dvt_1.header">
<xsl:with-param name="Rows" select="$Rows" />
</xsl:call-template>
<div class="blogRefineByAuthorContainer">
<xsl:call-template name="dvt_1.body">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template>
</div>
</xsl:template>
<xsl:template name="dvt_1.header">
<xsl:param name="Rows" />
<div class="blogRefineByAuthorEveryAuthor">Everyone</div>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:for-each select="$Rows">
<xsl:call-template name="dvt_1.rowview" />
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
<div class="blogRefineByAuthorAuthorTitle">
<xsl:value-of select="#Author.title" />
</div>
</xsl:template>
Any ideas of what it could be? Between the first and last name there is a space in the URL, but I don't think it makes any sense. I have tried with %20 without any result.
I have a xml as below that I'd like to copy n times while incrementing one of its element and one of its attribute.
XML input:
<?xml version="1.0"?>
<header xmlns="http://test.com" >
<Batch>
<test document="dump" >
<Person position=1>
<properties>
<name>John</name>
<number>1</number>
</properties>
</Person>
</test>
</Batch>
</header>
and I'd like something like below with the number of increment to be a variable.
XML output:
<?xml version="1.0"?>
<header xmlns="http://test.com" >
<Batch>
<test document="dump" >
<Person position=1>
<properties>
<name>John</name>
<number>1</number>
</properties>
</Person>
<Person position=2>
<properties>
<name>John</name>
<number>2</number>
</properties>
</Person>
...
<Person position=n>
<properties>
<name>John</name>
<number>n</number>
</properties>
</Person>
</test>
</Batch>
</header>
To solve this, I've started with the xslt below:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pTimes" select="2"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<xsl:call-template name="applyNTimes">
<xsl:with-param name="pTimes" select="$pTimes"/>
<xsl:with-param name="pPosition" select="1"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="applyNTimes">
<xsl:param name="pTimes" select="0"/>
<xsl:param name="pPosition" select="1"/>
<xsl:if test="$pTimes > 0">
<xsl:choose>
<xsl:when test="$pTimes = 1">
<xsl:apply-templates select="*">
<xsl:with-param name="pPosition" select="$pPosition"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="vHalf" select="floor($pTimes div 2)"/>
<xsl:call-template name="applyNTimes">
<xsl:with-param name="pTimes" select="$vHalf"/>
<xsl:with-param name="pPosition" select="$pPosition"/>
</xsl:call-template>
<xsl:call-template name="applyNTimes">
<xsl:with-param name="pTimes" select="$pTimes - $vHalf"/>
<xsl:with-param name="pPosition" select="$pPosition + $vHalf"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="Person">
<xsl:param name="pPosition" select="1"/>
<xsl:value-of select="$newline"/>
<Person position="{$pPosition}">
<xsl:apply-templates>
<xsl:with-param name="pPosition" select="$pPosition"/>
</xsl:apply-templates>
</Person>
</xsl:template>
<xsl:template match="number">
<xsl:param name="pPosition" select="1"/>
<number><xsl:value-of select="$pPosition"/></number>
</xsl:template>
</xsl:stylesheet>
but the output includes the namespace in elements. The element and attribute #position are always set to 1. Also, the header surrounds each element.
Please refer to the output below with n=2
<Batch xmlns="http://test.com">
<test document="dump">
<Person position="1">
<properties>
<name>John</name>
<number>1</number>
</properties>
</Person>
</test>
</Batch>
<Batch xmlns="http://test.com">
<test document="dump">
<Person position="1">
<properties>
<name>John</name>
<number>1</number>
</properties>
</Person>
</test>
</Batch>
Any clue?
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:t="http://test.com"
>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pTimes" select="2"/>
<xsl:template match="node()|#*">
<xsl:param name="pPosition" select="1"/>
<xsl:copy>
<xsl:apply-templates select="node()|#*">
<xsl:with-param name="pPosition" select="$pPosition"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="t:test">
<xsl:call-template name="applyNTimes">
<xsl:with-param name="pTimes" select="$pTimes"/>
<xsl:with-param name="pPosition" select="1"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="applyNTimes">
<xsl:param name="pTimes" select="0"/>
<xsl:param name="pPosition" select="1"/>
<xsl:if test="$pTimes > 0">
<xsl:choose>
<xsl:when test="$pTimes = 1">
<xsl:apply-templates select="*">
<xsl:with-param name="pPosition" select="$pPosition"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="vHalf" select="floor($pTimes div 2)"/>
<xsl:call-template name="applyNTimes">
<xsl:with-param name="pTimes" select="$vHalf"/>
<xsl:with-param name="pPosition" select="$pPosition"/>
</xsl:call-template>
<xsl:call-template name="applyNTimes">
<xsl:with-param name="pTimes" select="$pTimes - $vHalf"/>
<xsl:with-param name="pPosition" select="$pPosition + $vHalf"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="t:Person">
<xsl:param name="pPosition" select="1"/>
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:attribute name="position">
<xsl:value-of select="$pPosition"/>
</xsl:attribute>
<xsl:apply-templates>
<xsl:with-param name="pPosition" select="$pPosition"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="t:number">
<xsl:param name="pPosition" select="1"/>
<xsl:copy>
<xsl:value-of select="$pPosition"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document:
<header xmlns="http://test.com" >
<Batch>
<test document="dump" >
<Person position="1">
<properties>
<name>John</name>
<number>1</number>
</properties>
</Person>
</test>
</Batch>
</header>
produces the wanted results:
<header xmlns="http://test.com">
<Batch>
<Person position="1">
<properties>
<name>John</name>
<number>1</number>
</properties>
</Person>
<Person position="2">
<properties>
<name>John</name>
<number>2</number>
</properties>
</Person>
</Batch>
</header>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:t="http://test.com">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pTimes" select="2"/>
<xsl:template match="node()|#*">
<xsl:param name="pPosition" select="1"/>
<xsl:copy>
<xsl:apply-templates select="node()|#*">
<xsl:with-param name="pPosition" select="$pPosition"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="t:test">
<xsl:call-template name="applyNTimes">
<xsl:with-param name="pTimes" select="$pTimes"/>
<xsl:with-param name="pPosition" select="1"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="applyNTimes">
<xsl:param name="pTimes" select="0"/>
<xsl:param name="pPosition" select="1"/>
<xsl:if test="$pTimes > 0">
<xsl:choose>`enter code here`
<xsl:when test="$pTimes = 1">
<xsl:apply-templates select="*">
<xsl:with-param name="pPosition" select="$pPosition"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="vHalf" select="floor($pTimes div 2)"/>
<xsl:call-template name="applyNTimes">
<xsl:with-param name="pTimes" select="$vHalf"/>
<xsl:with-param name="pPosition" select="$pPosition"/>
</xsl:call-template>
<xsl:call-template name="applyNTimes">
<xsl:with-param name="pTimes" select="$pTimes - $vHalf"/>
<xsl:with-param name="pPosition" select="$pPosition + $vHalf"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="t:Person">
<xsl:param name="pPosition" select="1"/>
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:attribute name="position">
<xsl:value-of select="$pPosition"/>
</xsl:attribute>
<xsl:apply-templates>
<xsl:with-param name="pPosition" select="$pPosition"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="t:number">
<xsl:param name="pPosition" select="1"/>
<xsl:copy>
<xsl:value-of select="$pPosition"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>