How to do several ID sequence changes based on the ID prefix in several XHTML files?

How to do several ID sequence changes based on the ID prefix in several XHTML files?

49
Basic UserBasic User
49

    Feb 22, 2021#1

    I have some XHTML files. There are to do some ID sequence changes based on the prefix list given in prefix.lst containing lines like:

    Code: Select all

    part:pt
    chapter:c
    sec:h
    fig:f
    table:t
    box:b
    ref:r
    en:n
    eqn:e

    Step 1:

    The identifiers in the files should be changed according to the example given below:

    Code: Select all

    id="chapter1" = id="c1"
    id="chapter2" = id="c2"
    id="refintro_1" = id="r1"
    id="refintro_2" = id="r2"
    id="ref1_1" = id="r3"
    id="ref1_2" = id="r4"
    There are also has some other prefixes such as toc- and r_, which are prepended to the prefixes in the file prefix.lst,  which should be changed as shown in the example below:

    Code: Select all

    id="toc-chapter1" = id="c1b"
    id="toc-chapter2" = id="c2b"
    id="r_refintro_1" = id="r1b"
    id="r_refintro_2" = id="r2b"
    id="r_ref1_1" = id="r3b"
    id="r_ref1_2" = id="r4b"

    Step 2:

    Once the identifiers are changed in all files, the old identifiers used in the values of the href attributes should be changed according to the new identifiers. Example:

    Code: Select all

    href="#chapter1" = href="#c1"
    href="#chapter2" = href="#c2"
    href="#refintro_1" = href="#r1"
    href="#refintro_2" = href="#r2"
    href="#ref1_1" = href="#r3"
    href="#ref1_2" = href="#r4"
    
    href="#toc-chapter1" = href="#c1b"
    href="#toc-chapter2" = href="#c2b"
    href="#r_refintro_1" = href="#r1b"
    href="#r_refintro_2" = href="#r2b"
    href="#r_ref1_1" = href="#r3b"
    href="#r_ref1_2" = href="#r4b"
    Note: href attributes may contain the same identifiers multiple times.

    Step 3:

    Step 3 should change all aria-labelledby attributes in the same way as the id attributes above:

    Code: Select all

    aria-labelledby="secintro_1" = aria-labelledby="h1"
    aria-labelledby="sec1_1" = aria-labelledby="h2"
    
    aria-labelledby="tableintro_1" = aria-labelledby="t1"
    aria-labelledby="table1_1" = aria-labelledby="t2"
    Can the above three steps be done by a script?

    Thanks
    Update on 2021-02-25:

    Sorry, I made a mistake in saying that the ID sequence will be new in each file. Example:

    006-9781000419320_chapter1.xhtml

    Code: Select all

    id = "sec1_1" = id = "h1"
    id = "sec1_2" = id = "h2"
    id = "sec1_3" = id = "h3"
    
    007-9781000419320_chapter2.xhtml

    Code: Select all

    id = "sec2_1" = id = "h1"
    id = "sec2_2" = id = "h2"
    id = "sec2_3" = id = "h3"
    
    Of course from the prefix.lst list above part: pt and chapter: c will be omitted.

    I would be very grateful if anyone could help me with this.

    Update on 2021-03-04:

    Is it possible to create such a script? Please help me ...

    6,624550
    Grand MasterGrand Master
    6,624550

      Mar 04, 2021#2

      Yes, it is possible to code a script for that task. But it looks like it will take several hours to code and test the script as this is not a trivial task.

      There is missing the information about the directory structure.

      Is it possible that there are multiple XHTML files with identical name in different subdirectories of the project directory containing identifiers referenced from other XHTML files?

      project directory
      • part1
        • index.xhtml
        • page1.xhtml
        • page2.xhtml
      • part2
        • index.xhtml
        • page1.xhtml
        • page2.xhtml
      • part3
        • index.xhtml
        • page1.xhtml
        • page2.xhtml
      • index.xhtml
      In this case each XHTML file could reference any identifier in any other XHTML file and on updating references on changing an identifier in one XHTML file requires to take not only the file name left to # in a reference into account, but also the relative path to each file, which makes the task much more complex.

      The coding task is easier to solve if there can be excluded that there are files with identical names in different branches of the directory tree respectively all XHTML files are always in one directory.

      You have to wait until somebody is so friendly and spends several hours to code and test the UltraEdit script for this task for you for free. If you need a fast solution for the task because of a due date, I recommend to hire a programmer for coding it in whatever programming or scripting language being acceptable for you.
      Best regards from an UC/UE/UES for Windows user from Austria

      49
      Basic UserBasic User
      49

        Mar 06, 2021#3

        Thank you so much Mofi for your valuable reply.
        1. The directory structure can be any single directory and can have different subdirectories - according to your example.
        2. Each file will have the appropriate file destination completed and no place will be "#" without the file name. Without the file name only "#" means that the reference identifier is the identifier of its own file.
        To help understand this task - I attached the updated files below:
        • prefix.lst
        • Sample_Input1.zip
        • Sample_Output1.zip
        I know this task is a bit complicated, I would be very grateful if this task could be completed with an UltraEdit script.

        Thanks
        Sample_Output1.zip (18.55 KiB)   0
        Sample_Input1.zip (18.58 KiB)   0
        prefix.lst (124 Bytes)   0

        6,624550
        Grand MasterGrand Master
        6,624550

          Mar 06, 2021#4

          There is not answered one of my questions.

          Is it possible that there are multiple XHTML files with identical name in different subdirectories?

          Identical file names in different subdirectories makes the script extremely more difficult because of the relative file paths must be taken into account on updating references which excludes the usage of replace in files.
          Best regards from an UC/UE/UES for Windows user from Austria

          49
          Basic UserBasic User
          49

            Mar 06, 2021#5

            My files will be in a single folder, there will be no subdirectories, the file path will be set to the reference ID in the file

              Apr 05, 2021#6

              Is it possible to create such a script? Please help me ...