Click here to Skip to main content
15,885,546 members
Home / Discussions / XML / XSL
   

XML / XSL

 
AnswerRe: Transform XML Pin
TML6-Jul-17 10:50
TML6-Jul-17 10:50 
Questionsaving a file to the internet. Pin
felixjrz198531-May-17 21:54
felixjrz198531-May-17 21:54 
SuggestionRe: saving a file to the internet. Pin
Richard MacCutchan31-May-17 22:32
mveRichard MacCutchan31-May-17 22:32 
GeneralRe: saving a file to the internet. Pin
felixjrz19851-Jun-17 0:43
felixjrz19851-Jun-17 0:43 
GeneralRe: saving a file to the internet. Pin
Richard MacCutchan1-Jun-17 1:03
mveRichard MacCutchan1-Jun-17 1:03 
GeneralRe: saving a file to the internet. Pin
Gerry Schmitz1-Jun-17 3:20
mveGerry Schmitz1-Jun-17 3:20 
AnswerRe: saving a file to the internet. Pin
Terry Perez11-Sep-17 3:41
Terry Perez11-Sep-17 3:41 
QuestionXSLT passing a variable to starts-with Pin
bjmallon13-Feb-17 14:03
bjmallon13-Feb-17 14:03 
I've got an XML file full of user details including 'FirstName', 'Surname' and 'StreetAddress'.

Currently my XSL file has a template (SurnameAlphabetGrouping) that groups users by the first character of the Surname element's value. I've only provided the process for 'A' to save space. All 26 letters are processed.

XML
<xsl:template name="SurnameAlphabetGrouping">
    <xsl:variable name="AMatch" select="/Users/User[starts-with(Surname, 'A')]"/>
    <xsl:variable name="ACount" select="count($AMatch)"/>
    <xsl:if test="$ACount > 0">
      <h2>
        <a href="javascript:void(0)" class="dsphead" onclick="dsp(this)">
          + A (<xsl:value-of select="$ACount"/>)
        </a>
      </h2>
      <div class="dspcont">
        <table border="1" cellpadding="1" cellspacing="1">
          <tr>
            <xsl:call-template name="HeadingRow"/>
          </tr>

          <xsl:for-each select="/Users/User[starts-with(Surname, 'A')]">
            <xsl:sort select="Surname"/>
            <xsl:call-template name="UserRow"/>
          </xsl:for-each>
        </table>
      </div>
    </xsl:if>
  </xsl:template>


That's all well and good. But now that I've got it working that way, I really want to make it smarter (i.e. cut down the code), so I'm trying to build a template that can take the required character as a parameter.

I've got a variable (Letters) that carries tokens for the 26 letters of the alphabet:
XML
<xsl:variable name="Letters">
    <xsl:call-template name="tokenise">
      <xsl:with-param name="string" select ="'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'"/>
      <xsl:with-param name="delimeters" select="' '"/>
    </xsl:call-template>
  </xsl:variable>


I'm then attempting to process each token, passing it to the template as a parameter:
XML
<xsl:for-each select="msxsl:node-set($Letters)/token">
  <xsl:variable name="currToken" select ="./node()[1]"/>
  <xsl:call-template name="ListSurnameStartsWith">
    <xsl:with-param name="character" select="$currToken"/>
  </xsl:call-template>
</xsl:for-each>


This is the template as it stands at the moment:
XML
<xsl:template name="ListSurnameStartsWith">
    <xsl:param name="character" select="''"/>
    <xsl:variable name="charMatch" select="/Users/User[starts-with(Surname, $character)]"/>    
    <xsl:variable name="charCount" select="count($charMatch)"/>
    
      <xsl:if test="$charCount > 0">
      <h2>
        <a href="javascript:void(0)" class="dsphead" onclick="dsp(this)">
          + <xsl:value-of select="$character"/> (<xsl:value-of select="$charCount"/>)
        </a>
      </h2>
      <div class="dspcont">
        <table border="1" cellpadding="1" cellspacing="1">
          <tr>
            <xsl:call-template name="HeadingRow"/>
          </tr>

          <xsl:for-each select="/Users/User[starts-with(Surname, $character)]">
            <xsl:sort select="Surname"/>
            <xsl:call-template name="UserRow"/>
          </xsl:for-each>
        </table>
      </div>
    </xsl:if>
  </xsl:template>



'currToken' is getting the value I want. It's landing in the 'ListSurnameStartsWith' template just fine, but 'charMatch' just comes back blank all the time, meaning I can't get a meaningful count to test whether the output needs to be generated. The later '
AnswerRe: XSLT passing a variable to starts-with Pin
Richard Deeming14-Feb-17 2:32
mveRichard Deeming14-Feb-17 2:32 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon16-Feb-17 18:45
bjmallon16-Feb-17 18:45 
GeneralRe: XSLT passing a variable to starts-with Pin
Richard Deeming17-Feb-17 1:48
mveRichard Deeming17-Feb-17 1:48 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon20-Feb-17 22:55
bjmallon20-Feb-17 22:55 
GeneralRe: XSLT passing a variable to starts-with Pin
Richard Deeming21-Feb-17 1:42
mveRichard Deeming21-Feb-17 1:42 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon21-Feb-17 10:24
bjmallon21-Feb-17 10:24 
QuestionHow to generate XML file with serialisation in vb.net Pin
Member 1280320219-Oct-16 8:06
Member 1280320219-Oct-16 8:06 
Rant[REPOST] How to generate XML file with serialisation in vb.net Pin
Richard Deeming19-Oct-16 9:28
mveRichard Deeming19-Oct-16 9:28 
QuestionTransform the date format from yyyy/mm/dd to mm/dd/yyyy Pin
Member 1278840611-Oct-16 15:21
Member 1278840611-Oct-16 15:21 
AnswerRe: Transform the date format from yyyy/mm/dd to mm/dd/yyyy Pin
Richard Deeming12-Oct-16 3:26
mveRichard Deeming12-Oct-16 3:26 
QuestionRead xml string Pin
trungysp198610-Oct-16 14:48
trungysp198610-Oct-16 14:48 
AnswerRe: Read xml string Pin
Richard MacCutchan10-Oct-16 21:54
mveRichard MacCutchan10-Oct-16 21:54 
AnswerRe: Read xml string Pin
Swinkaran11-Oct-16 16:09
professionalSwinkaran11-Oct-16 16:09 
QuestionXML Pin
Member 1273144310-Sep-16 3:41
Member 1273144310-Sep-16 3:41 
AnswerRe: XML Pin
OriginalGriff10-Sep-16 3:44
mveOriginalGriff10-Sep-16 3:44 
GeneralRe: XML Pin
Member 1273144310-Sep-16 3:48
Member 1273144310-Sep-16 3:48 
GeneralRe: XML Pin
Member 1273144310-Sep-16 3:52
Member 1273144310-Sep-16 3:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.