[Solved] Dynamic search for Person and Title+ Releaseno, Serie, with Crosses

Discuss using and your tips/tricks for BookCAT
User avatar
Alex Ivanovich
Posts: 295
Joined: Mon Sep 07, 2015 2:24 pm
Location: Russian - Italia

Re: dynamic search for "Author" and "Title"

Post by Alex Ivanovich » Fri Nov 27, 2015 1:42 pm

I tried to put this code but does not work :|

Code: Select all

<xsl:choose>
              <xsl:when test="series='Super Super Almanacco Paperino (seconda serie)'"
	  <xsl:variable name="releaseno_with_crosses2"> <!-- solo per Super Super Almanacco Paperino (seconda serie) -->
          <xsl:value-of select="concat(substring('+++++++',1,5-string-length(releaseno/@integer)),releaseno/@integer)"/>
     </xsl:variable>
<a href="http://coa.inducks.org/issue.php?c=it/SAP{$releaseno_with_crosses2}"><xsl:text>  </xsl:text>Cerca su Inducks.org</a>
	           </xsl:when>
</xsl:choose>

User avatar
LotsOCds
Posts: 177
Joined: Thu Aug 20, 2015 4:23 am
Location: California, USA

Re: dynamic search for "Author" and "Title"

Post by LotsOCds » Fri Nov 27, 2015 4:09 pm

Try something like this. It may not be exactly what you want, I am trying to illustrate the logic.

Code: Select all

<xsl:variable name="releaseno_with_crosses">
  <xsl:value-of select="concat(substring('+++++++',1,5-string-length(releaseno/@integer)),releaseno/@integer)"/>      
</xsl:variable>

<xsl:choose>
  <xsl:when test="series='Super Almanacco Paperino'">
    <a href="http://coa.inducks.org/issue.php?c=it/SA{$releaseno_with_crosses}"><xsl:text>  </xsl:text>Cerca su Inducks.org SA</a>
  </xsl:when>
  
  <xsl:when test="series='Super Almanacco Paperino (seconda serie)'">
    <a href="http://coa.inducks.org/issue.php?c=it/SAP{$releaseno_with_crosses}"><xsl:text>  </xsl:text>Cerca su Inducks.org SAP</a>
  </xsl:when>
  
  <xsl:when test="series='Topolino (libretto)'">
    <a href="http://coa.inducks.org/issue.php?c=it/TL{$releaseno_with_crosses}"><xsl:text>  </xsl:text>Cerca su Inducks.org TL</a>
  </xsl:when>
  
  <xsl:otherwise>
  	<!-- Optional: Put a default link here for the case when there is no match to any of the xsl:when statements above -->
  </xsl:otherwise>
</xsl:choose>
Cheers,
Dave

User avatar
Alex Ivanovich
Posts: 295
Joined: Mon Sep 07, 2015 2:24 pm
Location: Russian - Italia

Re: dynamic search for "Author" and "Title"

Post by Alex Ivanovich » Fri Nov 27, 2015 6:18 pm

Hi Dave

ok, the code works, but there are problems with the link SAP :|

maybe you have to correct this :|

Code: Select all

<xsl:value-of select="concat(substring('+++++++',1,5-string-length(releaseno/@integer)),releaseno/@integer)"/>
analyzing the link (original site, only for these series, the others do not know), after slash, I calculated (between letters, crosses, and numbers) the length of Total 7 :roll:

Note: the links and variable, there may be five letters, one cross, and 1 number :|
I have not checked all the links, however,
:roll:


http://coa.inducks.org/issue.php?c=it/SA++++1 (work) links created from the code
2 letters
4 crosses Total 7
1 number

http://coa.inducks.org/issue.php?c=it/SA+++10 (work) links created from the code
2 letters
3 crosses Total 7
2 number


http://coa.inducks.org/issue.php?c=it/SAP++++1 (not work) links created from the code
3 letters
4 crosses Total 8
1 number

http://coa.inducks.org/issue.php?c=it/SAP+++1 (work) original link from INDUCKS
3 letters
3 crosses Total 7
1 number

Question: Why do I need this url?

Answer: I enter the series and the number in BookCAT, and save the record
then I need the url link to go to the site and find the exact comic to enter stories (the comics of Disney, contain many stories)
INDUCKS site catalogs all of the Disney comics worldwide

User avatar
Alex Ivanovich
Posts: 295
Joined: Mon Sep 07, 2015 2:24 pm
Location: Russian - Italia

Re: dynamic search for "Author" and "Title"

Post by Alex Ivanovich » Fri Nov 27, 2015 10:15 pm

I do not know if this is the right solution, but now also works with SAP

I created two variables

the first for SA and TL (are 2 letters initials)

the second for SAP (are 3 letters initials)

I changed in SAP string-length, from 1-5 to 1-4

we accept suggestions to improve code :idea:

code SA + TL

Code: Select all

<!-- Cerca su Inducks.org con stringhe speciali by Dave - inizio codice -->

                <xsl:variable name="releaseno_with_crosses">
  <xsl:value-of select="concat(substring('+++++++',1,5-string-length(releaseno/@integer)),releaseno/@integer)"/>     
</xsl:variable>

<xsl:choose>
  <xsl:when test="series='Super Almanacco Paperino (prima serie)'">
    <a href="http://coa.inducks.org/issue.php?c=it/SA{$releaseno_with_crosses}"><xsl:text>  </xsl:text>Cerca su Inducks.org SA</a>
  </xsl:when>
 
  
 
  <xsl:when test="series='Topolino (libretto)'">
    <a href="http://coa.inducks.org/issue.php?c=it/TL{$releaseno_with_crosses}"><xsl:text>  </xsl:text>Cerca su Inducks.org TL</a>
  </xsl:when>
 
  <xsl:otherwise>
     <!-- Optional: Put a default link here for the case when there is no match to any of the xsl:when statements above -->
  </xsl:otherwise>
</xsl:choose>

code SAP

Code: Select all

<!-- nuova variabile sulla string-length '+++++++',1,4-string-length -->
              <xsl:variable name="releaseno_with_crosses2">
  <xsl:value-of select="concat(substring('+++++++',1,4-string-length(releaseno/@integer)),releaseno/@integer)"/>     
</xsl:variable>

<xsl:choose>
<xsl:when test="series='Super Almanacco Paperino (seconda serie)'">
    <a href="http://coa.inducks.org/issue.php?c=it/SAP{$releaseno_with_crosses2}"><xsl:text>  </xsl:text>Cerca su Inducks.org SAP</a>
  </xsl:when>
</xsl:choose>
            <!-- nuova variabile sulla string-length '+++++++',1,4-string-length -->

User avatar
LotsOCds
Posts: 177
Joined: Thu Aug 20, 2015 4:23 am
Location: California, USA

Re: dynamic search for "Author" and "Title"

Post by LotsOCds » Sat Nov 28, 2015 1:59 am

I recommend code that looks like this. Calculate the variables first, then use one xsl:choose to pick the specific url. I have named the releaseno_with_crosses variables to indicate the total length of the string. Again, the code may not be exactly what you want but it does demonstrate how it should be structured.

Code: Select all

<xsl:variable name="releaseno_with_crosses_5">
  <xsl:value-of select="concat(substring('+++++++',1,5-string-length(releaseno/@integer)),releaseno/@integer)"/>      
</xsl:variable>
<xsl:variable name="releaseno_with_crosses_4">
  <xsl:value-of select="concat(substring('+++++++',1,4-string-length(releaseno/@integer)),releaseno/@integer)"/>      
</xsl:variable>

<xsl:choose>
  <xsl:when test="series='Super Almanacco Paperino'">
    <a href="http://coa.inducks.org/issue.php?c=it/SA{$releaseno_with_crosses_5}"><xsl:text>  </xsl:text>Cerca su Inducks.org SA</a>
  </xsl:when>

  <xsl:when test="series='Super Almanacco Paperino (seconda serie)'">
    <a href="http://coa.inducks.org/issue.php?c=it/SAP{$releaseno_with_crosses_4}"><xsl:text>  </xsl:text>Cerca su Inducks.org SAP</a>
  </xsl:when>

  <xsl:when test="series='Topolino (libretto)'">
    <a href="http://coa.inducks.org/issue.php?c=it/TL{$releaseno_with_crosses_5}"><xsl:text>  </xsl:text>Cerca su Inducks.org TL</a>
  </xsl:when>

  <xsl:otherwise>
  	<!-- Optional: Put a default link here for the case when there is no match to any of the xsl:when statements above -->
  </xsl:otherwise>
</xsl:choose>
Cheers,
Dave

User avatar
Alex Ivanovich
Posts: 295
Joined: Mon Sep 07, 2015 2:24 pm
Location: Russian - Italia

Re: dynamic search for "Author" and "Title"

Post by Alex Ivanovich » Sat Nov 28, 2015 5:19 am

LotsOCds wrote:I recommend code that looks like this. Calculate the variables first, then use one xsl:choose to pick the specific url. I have named the releaseno_with_crosses variables to indicate the total length of the string. Again, the code may not be exactly what you want but it does demonstrate how it should be structured.
Hi Dave
this code and better, I did not know that you could put two variables on the same code base, now I know ;)

could you explain this, because I discovered on the site INDUCKS that the code length can be up to 10 (or higher) :roll:

Code: Select all

+++++++',1,5-string-length
and this (I did not understand), with an example :roll:

Code: Select all

<xsl:otherwise>
     <!-- Optional: Put a default link here for the case when there is no match to any of the xsl:when statements above -->
  </xsl:otherwise>
I remember that SA, SAP, TL they are acronyms https://en.wikipedia.org/wiki/Acronym

SA equal Super Almanacco Paperino (prima serie) <-- first series

SAP equal Super Almanacco Paperino (seconda serie) <-- second series

TL equal Topolino (libretto)


thanks so much for the help ;)

User avatar
LotsOCds
Posts: 177
Joined: Thu Aug 20, 2015 4:23 am
Location: California, USA

Re: dynamic search for "Author" and "Title"

Post by LotsOCds » Sat Nov 28, 2015 6:00 am

could you explain this, because I discovered on the site INDUCKS that the code length can be up to 10 (or higher)

Code: Select all

substring('+++++++',1,4-string-length(releaseno/@integer))
The substring function returns the substring of the first argument starting at the position specified in the second argument with length specified in the third argument.

First argument: '+++++++' is string of plus signs

Second argument: 1 means the starting position is the first character

Third argument: 4-string-length(releaseno/@integer)
If releaseno=27, then string-length(releaseno/@integer)=2
So the third argument is 4-2=2

Therefore substring('+++++++',1,2) = '++'

Still using releaseno=27
concat(substring('+++++++',1,4-string-length(releaseno/@integer)),releaseno/@integer)
same as concat(substring('+++++++',1,2),'27')
same as concat('++','27')
Result is '++27'

If the length with plus signs needs to be 10 then you can do something like

Code: Select all

substring('++++++++++',1,10-string-length(releaseno/@integer))
and this (I did not understand), with an example
The <xsl:otherwise> element specifies a default action for the <xsl:choose> element. This action will take place when none of the <xsl:when> conditions apply.

In this example if $CATProgram='MSWord' the result will be 'This is not a CAT program'. Because none of the xsl:when statements match the default is to use the xsl:otherwise statement.

Code: Select all

<xsl:choose>
	<xsl:when test="$CATprogram = 'CATraxx'">
		This is CATraxx
	</xsl:when>
	
	<xsl:when test="$CATprogram = 'CATraxx'">
		This is CATraxx
	</xsl:when>
	
	<xsl:when test="$CATprogram = 'CATvids'">
		This is CATVids
	</xsl:when>
	
	<xsl:when test="$CATprogram = 'AssetCAT'">
		This is AssetCAT
	</xsl:when>

	<xsl:when test="$CATprogram = 'SoftCAT'">
		This is SoftCAT
	</xsl:when>

	<xsl:when test="$CATprogram = 'StampCAT'">
		This is StampCAT
	</xsl:when>
	
	<xsl:otherwise>
		This is not a CAT program
	</xsl:otherwise>
</xsl:choose>
Cheers,
Dave

User avatar
Alex Ivanovich
Posts: 295
Joined: Mon Sep 07, 2015 2:24 pm
Location: Russian - Italia

Re: dynamic search for "Author" and "Title"

Post by Alex Ivanovich » Sat Nov 28, 2015 6:51 am

wow, what perfect explanation :D
even if the strings I understand not much :shock: , but I understand the concept :D

Dave thank you very much for your help and patience, you are a great teacher ;)

I consider the issue solved (at the time) :)

User avatar
Alex Ivanovich
Posts: 295
Joined: Mon Sep 07, 2015 2:24 pm
Location: Russian - Italia

Re: [Solved] Dynamic search for Person and Title+ Releaseno, Serie, with Crosses

Post by Alex Ivanovich » Sat Nov 28, 2015 7:32 am

I reopen the topic :|
I have no problem with this url with apostrophe :|

http://www.diabolik.it/ricerca-risultati.php?cerca=L'inafferrabile Criminale (does not work

http://www.diabolik.it/ricerca-risultati.php?cerca=L inafferrabile Criminale ( works without apostrophe

Code: Select all

<xsl:choose>
                <xsl:when test="authors/author[1]/name='Diabolik'">
                <a href="http://www.diabolik.it/ricerca-risultati.php?cerca={title}"><xsl:text>  </xsl:text>Cersa su Diabolik.it</a>
                </xsl:when>

User avatar
LotsOCds
Posts: 177
Joined: Thu Aug 20, 2015 4:23 am
Location: California, USA

Re: Dynamic search for Person and Title+ Releaseno, Serie, with Crosses

Post by LotsOCds » Sat Nov 28, 2015 1:17 pm

This answer works well for simple character substitutions. If you have a more complicate substitution then a different method will be needed.

You will use the xsl function translate(string, string, string). This function translates characters in a string to other characters. Translation pairs are specified by the second and third strings. translate('A Space Odissei', 'i', 'y') would result in 'A Space Odyssey'. translate('abcdefg', 'aceg', 'ACE') result in 'AbCdEf'. The final g gets translated to nothing, because the third string has no counterpart for that position in the second string.

Translating an apostrophe does not work directly because the apostrophe is a delimiter character in XSL. To get around that we use a new variable "apos" in it's place. Put this code right where you created the 'sequenceno_with_crosses' variables.

Code: Select all

<xsl:variable name="apos">'</xsl:variable>
Now we are going to use translate(title,$apos,' ') instead of title in the url for Diabolik. What this does is replace the apostrophe with a space character.

Code: Select all

<xsl:choose>
  <xsl:when test="authors/author[1]/name='Diabolik'">
    <a href="http://www.diabolik.it/ricerca-risultati.php?cerca={translate(title,$apos,' ')}"><xsl:text>  </xsl:text>Cersa su Diabolik.it</a>
  </xsl:when>	
Cheers,
Dave

Post Reply